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

How to Add an Error Notice to Prevent the user from proceeding to checkout in WooCommerce?

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.

How to Add an Error Notice to Prevent the user from proceeding to checkout in WooCommerce?

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.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x