我应该创建一个函数来根据由3rd part插件实现的字段和帐单所在国家/地区取消税款,但是此代码不起作用。我在stackoverflow上尝试了其他解决方案,但没有任何效果。我的代码有什么问题?我也尝试了这段代码,但没有尝试Link
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["setTaxes"]) && $_COOKIE["setTaxes"] == 'no' ){
return "zero-rate";
}
return $tax_class;
}
add_action('wp_footer', 'payment_methods_trigger_update_checkout');
function payment_methods_trigger_update_checkout(){
?>
<script type="text/javascript">
jQuery(function($){
$(document).on('change','#billing_country',function(){
b_type = $("#billing_invoice_type :selected").val();
b_country = $("#billing_country :selected").val();
countryList = ['AT','LV','BE','LT','BG','LU','CZ','MT','CY','NL','HR','PL','DK','PT','EE','RO','FI','SK','FR','SI','DE','GR','SE','IE','HU'];
if (b_type == "invoice"){
if($.inArray(b_country, countryList) != -1){
console.log(b_type);
console.log(b_country);
document.cookie = "setTaxes=no";
$(document.body).trigger("update_checkout");
}else{
document.cookie = "setTaxes=yes";
$(document.body).trigger("update_checkout");
}
}else{
document.cookie = "setTaxes=yes";
$(document.body).trigger("update_checkout");
}
});
});
</script>
<?php
};