WC_GZD_Virtual_VAT_Helper

Virtual VAT Helper.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-gzd-virtual-vat-helper.php  
  1. class WC_GZD_Virtual_VAT_Helper { 
  2.  
  3. protected static $_instance = null; 
  4.  
  5. public static function instance() { 
  6. if ( is_null( self::$_instance ) ) 
  7. self::$_instance = new self(); 
  8. return self::$_instance; 
  9.  
  10. public function __construct() { 
  11. add_action( 'init', array( $this, 'init' ), 2 ); 
  12.  
  13. public function init() { 
  14. // Calculate taxes for virtual vat rates based on customer address if available 
  15. add_filter( 'woocommerce_base_tax_rates', array( $this, 'set_base_tax_rates' ), 10, 2 ); 
  16.  
  17. public function set_base_tax_rates( $rates, $tax_class ) { 
  18.  
  19. $location = WC_Tax::get_tax_location( $tax_class ); 
  20.  
  21. $virtual_vat_applicable = in_array( $tax_class, array( 'virtual-rate', 'virtual-reduced-rate' ) ) && isset( $location[0] ) && sizeof( $location ) === 4 && $location[0] !== WC()->countries->get_base_country(); 
  22.  
  23. if ( apply_filters( 'woocommerce_gzd_force_tax_location_vat_base_rates', $virtual_vat_applicable, $tax_class, $location ) ) { 
  24.  
  25. list( $country, $state, $postcode, $city ) = $location; 
  26.  
  27. $rates = WC_Tax::find_rates( array( 
  28. 'country' => $country,  
  29. 'state' => $state,  
  30. 'postcode' => $postcode,  
  31. 'city' => $city,  
  32. 'tax_class' => $tax_class 
  33. ) ); 
  34.  
  35. return $rates; 
  36.