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).
Additionally, you can also customize to display delivery day range based on shipping country in WooCommerce cart.
Where we need to paste this code. Please suggest
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.