Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
00 Days
00 Hours
00 Minutes
00 Seconds

How to Make Shipping Method Fields Mandatory on WooCommerce Checkout Page?

By default, one shipping method is always preselected. Occasionally, customers may unintentionally place an order without choosing a specific shipping method. Would you like to display a notice to customers prompting them to choose a shipping method? This code enables you to implement such a notice.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// Validate shipping method fields and returning an error if none is choosed
add_action( 'woocommerce_checkout_process', 'ts_shipping_method_validation', 20 );
function ts_shipping_method_validation() {
if ( ! isset( $_POST['shipping_method[0]'] ) ){
wc_add_notice( __( "You need to choose any of your shipping option.", "woocommerce" ), 'error' );
}
}
// Validate shipping method fields and returning an error if none is choosed add_action( 'woocommerce_checkout_process', 'ts_shipping_method_validation', 20 ); function ts_shipping_method_validation() { if ( ! isset( $_POST['shipping_method[0]'] ) ){ wc_add_notice( __( "You need to choose any of your shipping option.", "woocommerce" ), 'error' ); } }
// Validate shipping method fields and returning an error if none is choosed
add_action( 'woocommerce_checkout_process', 'ts_shipping_method_validation', 20 );
function ts_shipping_method_validation() {
    if ( ! isset( $_POST['shipping_method[0]'] ) ){
        wc_add_notice( __( "You need to choose any of your shipping option.", "woocommerce" ), 'error' );
    }
}

Output

When the customer doesn’t select any of the shipping methods and tries to place an order, will encounter an error message as shown below.

How to Make Shipping Method Fields Mandatory on WooCommerce Checkout Page?

In contrast to the above functionality, a store owner can also set one of your preferred shipping method as a preselected option always. Explore further here on how to set default shipping method 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
Paul
1 year ago

This looks excellent. But to work properly it presumable needs no shipping option to be preselected. How do I to stop WooCommerce preselecting an item please?

reCaptcha Error: grecaptcha is not defined
2
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.