Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
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.

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
2 months ago

Where we need to paste this code. Please suggest

Editor
2 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.

2
0
Would love your thoughts, please comment.x
()
x