
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:
- Checks Shipping Method: Retrieves the chosen shipping method(s) from the session.
- 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:
- Enable the WooCommerce shipping calculator on the cart page.
- Load the cart page without entering a shipping address and check for the notice.
- 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.