Search
Close this search box.
Search
Close this search box.

WooCommerce Notices

Notice types

WooCommerce uses 3 notice types: success, error and notice.

Success

A ‘success’ message when something is successful, for example after adding an item to the cart, or getting a shipping quote.

Error

An ‘error’ message triggered when something goes wrong, either user fault or code.

Notice

A generic notice type which is neither an error nor a success message.

Adding a notice

The main function is to add a notice is wc_add_notice. Once added, the notice is queued and will be output and cleared when WooCommerce outputs notices before a loop.

wc_add_notice( $message, $notice_type = 'success' );

Translating a notice

wc_add_notice(__('The notice I want to translate', 'my-text-domain'), 'error');

Using sprintf with WooCommerce notices

Always use sprintf when using WooCommerce notices. It makes code much easier to read.

wc_add_notice( sprintf('You must have an order with a minimum of %s to place your order, your current order total is %s.', woocommerce_price($minimum), woocommerce_price(WC()->cart->total)), 'error' );

Learning Resources