Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
00 Days
00 Hours
00 Minutes
00 Seconds

How to Show Custom Message in WooCommerce Checkout based on Shipping Country?

Are you looking to display delivery timeframes based on the customer’s shipping country after order processing? If so, this code snippet provides a notice based on the country.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
add_action( 'woocommerce_checkout_before_customer_details', 'ts_display_shipping_notice' );
function ts_display_shipping_notice() {
echo '<div class="shipping-notice woocommerce-message" role="alert" style="display:none">Please allow 5-10 business days for delivery after order processing.</div>';
}
add_action( 'woocommerce_after_checkout_form', 'ts_show_shipping_notice_js' );
function ts_show_shipping_notice_js(){
?>
<script>
jQuery(function($){
var countryCode = 'IN', // Set the country code (That will display the message)
countryField = 'select#billing_country'; // The Field selector to target
function ts_showHideShippingNotice( countryCode, countryField ){
if( $(countryField).val() === countryCode ){
$('.shipping-notice').show();
}
else {
$('.shipping-notice').hide();
}
}
// On Ready (after DOM is loaded)
ts_showHideShippingNotice( countryCode, countryField );
// On billing country change (Live event)
$('form.checkout').on('change', countryField, function() {
ts_showHideShippingNotice( countryCode, countryField );
});
});
</script>
<?php
}
add_action( 'woocommerce_checkout_before_customer_details', 'ts_display_shipping_notice' ); function ts_display_shipping_notice() { echo '<div class="shipping-notice woocommerce-message" role="alert" style="display:none">Please allow 5-10 business days for delivery after order processing.</div>'; } add_action( 'woocommerce_after_checkout_form', 'ts_show_shipping_notice_js' ); function ts_show_shipping_notice_js(){ ?> <script> jQuery(function($){ var countryCode = 'IN', // Set the country code (That will display the message) countryField = 'select#billing_country'; // The Field selector to target function ts_showHideShippingNotice( countryCode, countryField ){ if( $(countryField).val() === countryCode ){ $('.shipping-notice').show(); } else { $('.shipping-notice').hide(); } } // On Ready (after DOM is loaded) ts_showHideShippingNotice( countryCode, countryField ); // On billing country change (Live event) $('form.checkout').on('change', countryField, function() { ts_showHideShippingNotice( countryCode, countryField ); }); }); </script> <?php }
add_action( 'woocommerce_checkout_before_customer_details', 'ts_display_shipping_notice' );
function ts_display_shipping_notice() {
    echo '<div class="shipping-notice woocommerce-message" role="alert" style="display:none">Please allow 5-10 business days for delivery after order processing.</div>';
}

add_action( 'woocommerce_after_checkout_form', 'ts_show_shipping_notice_js' );
function ts_show_shipping_notice_js(){
    ?>
    <script>
        jQuery(function($){
            var countryCode  = 'IN', // Set the country code (That will display the message)
                countryField = 'select#billing_country'; // The Field selector to target
            
            function ts_showHideShippingNotice( countryCode, countryField ){
                if( $(countryField).val() === countryCode ){
                    $('.shipping-notice').show();
                }
                else {
                    $('.shipping-notice').hide();
                }
            }

            // On Ready (after DOM is loaded)
            ts_showHideShippingNotice( countryCode, countryField );

            // On billing country change (Live event)
            $('form.checkout').on('change', countryField, function() {
                ts_showHideShippingNotice( countryCode, countryField );
            });
        });
    </script>
    <?php
}

Output

The above snippet adds a shipping notice to the checkout page, informing customers about the expected delivery time. The shipping notice is displayed only if the selected billing country is set to ‘IN’ (India).

How to Show Custom Message in WooCommerce Checkout based on Shipping Country?

Additionally, you can also customize to display delivery day range based on shipping country in WooCommerce cart.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of


2 Comments
Newest
Oldest
Inline Feedbacks
View all comments
Farman
10 months ago

Where we need to paste this code. Please suggest

Editor
10 months ago
Reply to  Farman

Hi Farman,

You can add the code snippets to the functions.php file of your child theme. The file can be found at Appearance -> Theme File Editor -> and then from the right sidebar you can find the functions.php file. Another easy option is to install the Code Snippets plugin, which lets you add code snippets directly through the plugin interface. Feel free to reach out if you have any questions or need further clarification.

reCaptcha Error: grecaptcha is not defined
2
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.