Display a notice on WooCommerce checkout page for specific countries

How to display a notice on the checkout page only to visitors from specific countries?

As COVID-19 spread around the globe, businesses adjusted. But not all of them – particularly the ones in the government sector. This is especially the case with government shipping companies all over the world. 

Due to disruption in their service, customers experienced a huge delay in delivery times, sometimes more than a month from the order date. To manage customer’s expectations, it’s important to let them know that deliveries might be delayed for a certain amount of time. And one of the best ways to catch visitors attention is to add a notice on the checkout page while they’re filling billing/shipping information. 

Hooking a function to woocommerce_before_checkout_billing_form to display a notice on the checkout page is straightforward enough, but what if you want to display the notice ONLY to visitors from specific countries? JS comes to the rescue. Just stick the whole code from below to your functions.php and let me know in the comments section below if it doesn’t work anymore! 

Don’t forget to modify your shipping notice message text and add specific country codes to have this notice displayed ONLY for visitors from those countries. 


// Displays a notice for International customers on the checkout page 

add_action( 'woocommerce_before_checkout_billing_form', 'sf_international_shipping_notice' );

function sf_international_shipping_notice() { 

echo '<div class="international-shipping-notice woocommerce-info" style="display:none; color:red"><b style="color:red;">Note:</b> Your shipping notice message. </div>'; } 

add_action( 'woocommerce_after_checkout_form', 'sf_show_international_shipping_notice' ); 

function sf_show_international_shipping_notice(){ ?>

<script> jQuery(document).ready(function($){ 
var countryCode = ["AU", "AT", "Any_other_country_code_you_want_to_include"]; 

$('select#billing_country').change(function(){ 
selectedCountries = $(this).val(); 

if (countryCode.some(r => selectedCountries.includes(r))){ 
$('.international-shipping-notice').show(); 
} else { 

$('.international-shipping-notice').hide(); } }); }); </script> }
 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top