How to Display Shipping Message After Country Selection at Checkout?

If your shipping is limited to specific countries, then this article is for you! In WooCommerce, you can display shipping messages after one selects delivery location. This is how you can showcase personalized delivery messages for every single country. It also gives highly personalized delivery information to your customers. In this article, you will learn how to display shipping message after country selection at WooCommerce checkout page. 

You can enable this country-specific function with a simple PHP code. One can even customize this snippet based on target state selections. So, you can show conditional delivery messages after your website customer selects the desired country. Nevertheless, it will also enhance website’s user experience. Enjoy reading! 

Image suggesting to display message after country selection at WooCommerce checkout

PHP Snippet: Display Shipping Message After Country Selection at WooCommerce Checkout

// Part 1
// Add the message notification and place it over the billing section
// The "display:none" hides it by default
  
add_action( 'woocommerce_before_checkout_billing_form', 'phpsof_echo_notice_shipping' );
  
function phpsof_echo_notice_shipping() {
echo '<div class="shipping-notice woocommerce-info" style="display:none">Please allow 5-10 business days for delivery after order processing.</div>';
}
  
// Part 2
// Show or hide message based on billing country
// The "display:none" hides it by default
  
add_action( 'woocommerce_after_checkout_form', 'phpsof_show_notice_shipping' );
  
function phpsof_show_notice_shipping(){
     
    ?>
  
    <script>
        jQuery(document).ready(function($){
  
            // Set the country code (That will display the message)
            var countryCode = 'FR';
  
            $('select#billing_country').change(function(){
  
                selectedCountry = $('select#billing_country').val();
                  
                if( selectedCountry == countryCode ){
                    $('.shipping-notice').show();
                }
                else {
                    $('.shipping-notice').hide();
                }
            });
  
        });
    </script>
  
    <?php
     
}

Where do you add this snippet?

So, this is how you can display shipping message after country selection at WooCommerce checkout page. Also, it is easier to activate this function with this code. So, to apply this code, just add this PHP snippet at your child theme function.php file’s bottom. It should be placed before “?>”, if you have it there. Apart from this, CSS goes in your child theme style.css file. Make sure that you are editing these files in a right manner for best results.

Is this snippet still valid?

So, this is how you can learn about display shipping message at WooCommerce checkout page. I have applied this code on the Storefront theme and WordPress friendly hosting PHP 7.3. Let me know if everything works as expected when you code. Share it further if you find this snippet useful for you and it had saved your time. 

Also Read, How to Add Checkout Fee for Payment Gateway in WooCommerce?

How to Remove or Move Login or Registration at Checkout?

Important links: WooCommerce – https://woocommerce.com/