使用PHP代码而无需重新加载页面(表单)
问题描述:
I am trying to use this code for my woocommerce shop so the taxes won't show if the shipping country switzerland is selected. The problem is, that it only works on a page reload.. if the user selects switzerland in the form it does not change immediately.. is there a way it constantly checks if the country is ch?
<?php global $woocommerce;
$county = array('CH');
if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) ) :
echo "<style> .order-tax {display:none;} </style>";
endif;
?>
我正在尝试将此代码用于我的woocommerce商店,因此如果运输国瑞士是 选择。 问题是,它只适用于页面重新加载..如果用户选择瑞士的形式它不会立即改变..有没有办法不断检查国家是否ch? p>
&lt;?php global $ woocommerce;
$ county = array('CH');
if(in_array($ woocommerce-&gt; customer-&gt; get_shipping_country(),$ county)) :
echo“&lt; style&gt; .order-tax {display:none;}&lt; / style&gt;”;
endif;
?&gt;
code> pre>
div>
答
You need to use jQuery for that
$(document).ready(function(){
$('#billing_country').on('change', function() {
if ($(this).val() == 'CH')
$('.order-tax').css('display', 'none');
else
$('.order-tax').css('display', 'block');
});
});