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. if ( 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. list( $country, $state, $postcode, $city ) = $location; 
  24.  
  25. $rates = WC_Tax::find_rates( array( 
  26. 'country' => $country,  
  27. 'state' => $state,  
  28. 'postcode' => $postcode,  
  29. 'city' => $city,  
  30. 'tax_class' => $tax_class 
  31. ) ); 
  32.  
  33.  
  34. return $rates; 
  35.  
  36.