If you wish to display shipping selection notifications to your customers on the cart page before finalizing their order, the following code snippet may prove useful.
add_action( 'woocommerce_check_cart_items', 'ts_shipping_methods' ); function ts_shipping_methods() { $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); if( is_array( $chosen_shipping_methods ) && count( $chosen_shipping_methods ) > 0 ) { // Display an error message wc_add_notice( __("A shipping method is required in order to proceed to checkout."), 'error' ); } }
Output
This code snippet is hooked to the woocommerce_check_cart_items action. Its purpose is to add an error notice when the user tries to checkout without selecting a shipping method.
You can also add message for out-of-delivery area warning in WooCommerce cart page. This can help display delivery timeframes or any other relevant information specific to the customer’s location.