我正在尝试在结帐页面的结算设置中添加基于所选国家/地区的通知。 当我放置1个或2个国家/地区时,我发现能正常工作的代码。但是,一旦我添加了更多国家/地区,代码便无法正常工作。有人知道为什么吗?
有效的代码:
add_action( 'woocommerce_before_checkout_billing_form', 'bbloomer_echo_notice_shipping' );
function bbloomer_echo_notice_shipping() {
echo '<div class="shipping-notice woocommerce-info" style="display:none">My message goes here</div>';
}
// Show or hide message based on billing country
// The "display:none" hides it by default
add_action( 'woocommerce_after_checkout_form', 'bbloomer_show_notice_shipping' );
function bbloomer_show_notice_shipping(){
?>
<script>
jQuery(document).ready(function($){
// Set the country code (That will display the message)
var countryCode = 'AT';
var countryCode = 'BE';
var countryCode = 'BG';
$('select#billing_country').change(function(){
selectedCountry = $('select#billing_country').val();
if( selectedCountry == countryCode ){
$('.shipping-notice').show();
}
else {
$('.shipping-notice').hide();
}
});
});
</script>
<?php
无效的代码:
add_action( 'woocommerce_before_checkout_billing_form', 'bbloomer_echo_notice_shipping' );
function bbloomer_echo_notice_shipping() {
echo '<div class="shipping-notice woocommerce-info" style="display:none">My message goes here.</div>';
}
// Show or hide message based on billing country
// The "display:none" hides it by default
add_action( 'woocommerce_after_checkout_form', 'bbloomer_show_notice_shipping' );
function bbloomer_show_notice_shipping(){
?>
<script>
jQuery(document).ready(function($){
// Set the country code (That will display the message)
var countryCode = 'AT';
var countryCode = 'BE';
var countryCode = 'BG';
var countryCode = 'HR';
var countryCode = 'DK';
var countryCode = 'FR';
var CountryCode = 'SI';
var CountryCode = 'SE';
var CountryCode = 'PL';
var CountryCode = 'RS';
var CountryCode = 'ES';
$('select#billing_country').change(function(){
selectedCountry = $('select#billing_country').val();
if( selectedCountry == countryCode ){
$('.shipping-notice').show();
}
else {
$('.shipping-notice').hide();
}
});
});
</script>
<?php
任何人都知道为什么在尝试将更多国家/地区添加到列表时代码不起作用?