我正试图将此代码用于我的wooccommerce商店,因此如果选择了发货国瑞士,则不会显示税款。问题是,它只适用于重新加载页面。。如果用户在表单中选择瑞士,则不会立即更改。。有没有办法经常检查这个国家是否是ch?
<?php global $woocommerce;
$county = array('CH');
if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) ) :
echo "<style> .order-tax {display:none;} </style>";
endif;
?>
您需要对使用jQuery
$(document).ready(function(){
$('#billing_country').on('change', function() {
if ($(this).val() == 'CH')
$('.order-tax').css('display', 'none');
else
$('.order-tax').css('display', 'block');
});
});