【发布时间】:2021-12-24 15:46:30
【问题描述】:
我在结帐时使用 BBloomer 的修改后的 sn-p。
我查找所选国家/地区,如果国家/地区是挪威“否”,它会在有关非欧盟国家/地区的 TAX 信息的总额之后回显一条消息。
由于我们现在也向英国和 Switcherland 发货,因此我想在 mu 脚本中包含这些国家/地区。
这意味着 var countryCode = 'NO';应该类似于 var countryCode = array('NO','UK','CH');还是?
其他强大的也需要处理数组而不是单个值。
希望任何人都可以提供帮助。
// The message
add_action( 'woocommerce_review_order_after_order_total', 'bbloomer_echo_notice_shipping' );
function bbloomer_echo_notice_shipping() {
echo '<tr class="non-eu-tax-notice" style="display:none">
<th>'. __( 'Notice', 'woocommerce' ) .'</th>
<td data-title=" '. __( 'Notice', 'woocommerce' ) .' ">'. __( 'No VAT charged. Please be aware that VAT and customs can be declared in your home country. More info here', 'woocommerce' ) .'</td>
</tr>';
}
// Show or hide message based on billing country
add_action( 'woocommerce_checkout_after_order_review', 'bbloomer_show_notice_shipping' );
function bbloomer_show_notice_shipping(){
wc_enqueue_js( "
// Set the country code that will display the message
var countryCode = 'NO';
// Get country code from checkout
selectedCountry = $('select#billing_country').val();
// Function to toggle message
function toggle_upsell( selectedCountry ) {
if( selectedCountry == countryCode ){
$('.non-eu-tax-notice').show();
}
else {
$('.non-eu-tax-notice').hide();
}
}
// Call function
toggle_upsell( selectedCountry );
$('select#billing_country').change(function(){
toggle_upsell( this.value );
});
" );
}
【问题讨论】:
标签: php woocommerce checkout