【发布时间】:2021-04-24 19:06:20
【问题描述】:
我目前正在使用下面的代码来显示基于国家/地区的自定义消息:
add_action( 'woocommerce_before_checkout_billing_form', 'display_shipping_notice' );
function display_shipping_notice() {
echo '<div class="shipping-notice woocommerce-info" style="display:none">Please allow 5-10 business days for delivery after order processing.</div>';
}
add_action( 'woocommerce_after_checkout_form', 'show_shipping_notice_js' );
function show_shipping_notice_js(){
?>
<script>
jQuery(document).ready(function($){
// Set the country code (That will display the message)
var countryCode = 'GB';
$('select#billing_country').change(function(){
selectedCountry = $('select#billing_country').val();
if( selectedCountry == countryCode ){
$('.shipping-notice').show();
}
else {
$('.shipping-notice').hide();
}
});
});
</script>
<?php
}
此代码的问题在于,它只会在更改或选择国家/地区时显示消息。但是,大多数客户已经预先填写了他们的国家/地区,因此不会显示自定义消息。
我正在尝试找到一种方法来更改代码,以便在选择正确的国家/地区时始终显示消息。
【问题讨论】:
标签: php wordpress woocommerce checkout notice