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
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x