How to display conditional cart notices in WooCommerce
WooCommerce does not provide a dashboard setting for conditional cart notices, but you can add one with PHP on the classic cart page. For product, category, quantity, amount, deadline and checkout conditions, a cart-notice plugin is quicker and easier to maintain.
- 01Define the notice condition
- 02Add the manual cart notice
- 03Handle checkout and cart blocks
- 04Test the condition properly
- 05Install a conditional notice plugin
- 06Set placement and publish
What you need
- A WooCommerce store with a working cart page
- Administrator access to WordPress
- A child theme or code-snippets tool for the manual route
- The message and condition you want to display
Define the notice condition
Decide exactly when the message should appear. Common rules include a particular product in the cart, a category being present, a minimum cart total, a quantity range, or a deadline for an offer.
Keep the message useful and specific, such as “Add one more item to qualify for free shipping”. Avoid showing the same notice after the customer has already met the condition.
Add the manual cart notice
For a classic WooCommerce cart page, add a function to your child theme or a code-snippets tool and attach it to woocommerce_before_cart. The function can inspect WC()->cart->get_cart(), check each cart item, and output a message with wc_print_notice().
A simple product check uses the product ID in the cart item’s product_id value. Replace 123 with the product ID you need:
add_action( 'woocommerce_before_cart', 'gplwp_conditional_cart_notice' ); function gplwp_conditional_cart_notice() { if ( ! WC()->cart ) { return; } foreach ( WC()->cart->get_cart() as $cart_item ) { if ( 123 === (int) $cart_item['product_id'] ) { wc_print_notice( 'This item qualifies for our special offer.', 'notice' ); break; } } }
This route is fine for one or two stable rules, but it requires PHP maintenance, does not provide an editor for store staff, and the hook is intended for the classic cart template. WooCommerce documents woocommerce_before_cart as the action before the cart contents are displayed.
Handle checkout and cart blocks
If the notice must also appear at checkout, use the appropriate checkout action, such as woocommerce_before_checkout_form, and test it separately. Do not assume that code attached to the classic cart template will behave the same way in Cart and Checkout blocks.
Legacy hooks and queued notices have limited or different support in blocks. If your cart page uses blocks and the message does not appear, confirm the page layout before changing the condition or adding duplicate code.
Test the condition properly
Test both sides of the rule: a cart that should show the notice and a cart that should not. Check adding and removing products, changing quantities, applying coupons, refreshing the page, and moving from cart to checkout.
Test while logged out and on a phone as well. A common Friday-afternoon failure is a notice that appears twice because it is printed directly and also added to WooCommerce’s notice queue. Use one output method and clear any duplicate snippet before testing again.
Install a conditional notice plugin
For several rules, scheduled campaigns or notices managed by non-developers, install WooCommerce Cart Notices from the WordPress Plugins area and activate it. Its settings add a Cart Notices screen where you can create, enable, disable and edit notices.
The documented notice types include minimum amount, deadline, referrer, products in cart and categories in cart. You can also add a call-to-action button and use variables such as the remaining amount, matching products or cart quantity.
Set placement and publish
Create the message, choose its condition, set any minimum or maximum amount or quantity, and select the products or categories that control it. For a deadline notice, set the active days and deadline time. Keep the call to action optional unless it takes the customer to a relevant page.
Use the plugin’s default cart or checkout placement first. If you need the notice elsewhere, its documented shortcodes can place all notices or a named notice on another page. Choose WooCommerce Cart Notices when timely, conditional messages matter more than abandonment tracking or recovery.
Let WooCommerce Cart Notices do it
Conditional, scheduled messages for carts and checkout; choose it when timely notices matter more than abandonment tracking or recovery.
Sources
- woocommerce.com /document/actions-and-filters/?utm_source=openai
- github.com /woocommerce/woocommerce/blob/trunk/docs/block-development/r…
- woocommerce.com /document/woocommerce-cart-notices/?utm_source=openai
Questions
- Can WooCommerce display conditional cart notices without a plugin?
- Yes, WooCommerce can display a conditional notice with custom PHP, but it does not provide a built-in admin screen for managing those rules. A developer can check the cart contents and output a message through a cart action such as <code>woocommerce_before_cart</code>. Use a plugin when staff need to edit conditions, schedule campaigns or manage many notices.
- Which hook displays a notice before the WooCommerce cart?
- The <code>woocommerce_before_cart</code> action runs before the cart contents are displayed on the classic WooCommerce cart page. Attach a function to it, inspect the cart, and print the message only when the condition is true. For checkout, use an appropriate checkout action and test it separately because cart and checkout templates are not interchangeable.
- Why is my conditional cart notice not showing?
- The most common cause is that the page uses the Cart or Checkout block rather than the classic shortcode-based template. Legacy PHP hooks and queued notices have limited or different block support. Other causes include checking the wrong product ID, placing the condition after the notice is printed, or testing an AJAX cart update that does not reload the page.
- Can I show a notice for a minimum cart total or quantity?
- Yes, both are possible. In custom code, compare the cart total or quantity against your chosen threshold before printing the notice. A cart-notice plugin provides fields for minimum and maximum amounts or quantities, which is safer when store staff need to adjust the threshold without editing PHP.
- What is the fastest way to create several scheduled cart notices?
- Use WooCommerce Cart Notices. It provides an admin screen for notices based on cart amount, deadline, referrer, products or categories, with optional call-to-action buttons and message variables. This is faster than maintaining several snippets and is the better route when notices need dates, multiple conditions or checkout placement.