To make it work, you will better target the WC_Product
method get_tax_class()
through dedicated related composite hooks, this way:
add_filter('woocommerce_product_get_tax_class', 'switch_product_tax_class', 100, 2 );
add_filter('woocommerce_product_variation_get_tax_class', 'switch_product_tax_class', 100, 2 );
function switch_product_tax_class( $tax_class, $product ){
if( isset($_COOKIE["customerType"]) && $_COOKIE["customerType"] == 'business' ){
return "Zero Rate";
}
return $tax_class;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Based on WC_Customer
is_vat_exempt
property, you could also try to use the following instead:
add_action( 'template_redirect', 'vat_exempt_b2b_customers' );
function vat_exempt_b2b_customers() {
if( isset($_COOKIE["customerType"]) && $_COOKIE["customerType"] === 'business'
&& ! WC()->customer->is_vat_exempt() ){
WC()->customer->set_is_vat_exempt( true );
}
}
Code goes in functions.php file of your active child theme (or active theme).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…