Я пытаюсь добавить уведомление на основе выбранной страны в настройках биллинга на странице оформления заказа. Я нашел код, который работает нормально, когда я размещаю 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
Кто-нибудь знает, почему код не работает при попыткедобавить больше стран в список?