Displaying a Cart Notice for Missing Shipping Information in WooCommerce

A Business Bloomer Club member recently asked about adding a cart notice in WooCommerce to prompt customers to enter their postal code in the shipping calculator.

They noted that customers sometimes overlook this step, leading to confusion when no shipping options are available.

Below, we’ll walk through a method to display a notice at the top of the cart page, reminding customers to add their address information to view shipping options.

Step 1: Understanding WooCommerce Notices

WooCommerce allows custom notices on various pages, which can be especially helpful to guide customers. In this case, we want the notice to appear at the top of the cart page if no shipping options are selected, prompting the user to enter their address.

Step 2: Code Snippet to Add a Cart Notice

Here’s a snippet that accomplishes this. It checks if the customer has chosen a shipping method and, if not, displays a notice asking them to enter their postal code:

function add_notice_no_shipping_selected() {
    $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');

    // If no shipping method has been selected, display the notice
    if (empty($chosen_shipping_methods)) {
        $notice = 'Please enter your postcode above to display shipping options.';
        wc_print_notice($notice, 'notice');
    }
}
add_action('woocommerce_before_cart', 'add_notice_no_shipping_selected', 1);

This snippet:

  1. Checks Shipping Method: Retrieves the chosen shipping method(s) from the session.
  2. Displays a Notice: If no shipping method is selected, it shows a message at the top of the cart page prompting customers to enter their postal code.

Step 3: Testing the Notice

To ensure this notice appears as expected:

  1. Enable the WooCommerce shipping calculator on the cart page.
  2. Load the cart page without entering a shipping address and check for the notice.
  3. Verify that the notice disappears once a valid postal code is entered.

This approach provides clear guidance to customers, making it more likely they’ll complete the shipping calculation step, which improves their overall shopping experience. For more customizations, refer to Business Bloomer’s tutorial on WooCommerce cart notices.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

Your email address will not be published. Required fields are marked *