I’m trying with the code below to set to zero rate the tax when selling to a European Union state an order of value above 150 euro but I can’t get it to work. Any idea what I’m doing wrong?
JavaScript
x
add_filter( 'woocommerce_product_get_tax_class', 'eu_tax_rate_based_on_subtotal', 1, 2 );
function eu_tax_rate_based_on_subtotal( $tax_class, $product ) {
$EU_countries = array('AT','BE','BG','CY','CZ','DE','DK','EE','ES','FI','FR','GR','HR','HU','IE','IT','LT','LU','LV','MT','NL','PL','PT','RO','SE','SI','SK');
if ( in_array( WC()->customer->get_shipping_country(), $EU_countries ) ){
if ( WC()->cart->subtotal >= 150 )
$tax_class = 'zero';
}
return $tax_class;
}
Advertisement
Answer
Use this filter if you want to remove taxes without a dynamic requirements.
JavaScript
function sto_calc_tax($taxes, $price, $rates, $price_includes_tax, $deprecated){
if (WC()->cart->subtotal >= 150 && in_array( WC()->customer->get_shipping_country(), array('AT','BE','BG','CY','CZ','DE','DK','EE','ES','FI','FR','GR','HR','HU','IE','IT','LT','LU','LV','MT','NL','PL','PT','RO','SE','SI','SK') ) ){
foreach ($taxes as $index => $tax) {
$taxes[$index] = 0;
}
}
return $taxes;
}
add_filter('woocommerce_calc_tax', 'sto_calc_tax', 10, 5);