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.
// 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? 1 How to Make Shipping Method Fields Mandatory on WooCommerce Checkout Page?](https://media.tychesoftwares.com/wp-content/uploads/validate-shipping-method-options-1024x760.png)
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.
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?
Hi Paul,
We have drafted a new post based on your requirement. Please check out this post- How to Remove the Default Pre-selected Shipping Method on the Checkout Page in WooCommerce?