Remove the Added to Cart Message in WooCommerce

When a customer adds a product to the cart, WooCommerce shows a notice on the next page: “Product has been added to your cart.” with a View cart button. With a side cart or a one-page checkout, that notice gets in the way, and its button sends people to the cart page you want them to skip.

This one-line WooCommerce snippet removes the “added to your cart” message. Every other notice, such as stock errors and coupon messages, still shows.

The snippet

<?php
/**
 * Remove the WooCommerce "… has been added to your cart. View cart" message.
 */
add_filter( 'wc_add_to_cart_message_html', '__return_empty_string' );

Add it with Scripts Organizer

In Scripts Organizer go to Code Blocks → Add New and give the block a name. Set Trigger location to Everywhere, tick PHP under Script location, paste the code into the PHP editor and publish. Leave Action/Hook empty.

The code only adds a filter, so it can load before WooCommerce. Everywhere also covers add to cart requests through admin-ajax.php and the Store API.

The same code also works unchanged in a small plugin or an mu-plugin.

How it works

  • After a product is added, WooCommerce builds the message in wc_add_to_cart_message() and passes the HTML through the wc_add_to_cart_message_html filter.
  • __return_empty_string is a core WordPress helper that returns ''. With an empty message, WooCommerce does not queue a notice at all, so no empty box shows up either.
  • Only this message is affected. Notices added with wc_add_notice() elsewhere keep working.
  • The older version returned null with __return_null. The filter expects a string, so an empty string is the correct value.

Customise it

  • Send customers straight to checkout after adding a product: add add_filter( 'woocommerce_add_to_cart_redirect', 'wc_get_checkout_url' ); below the snippet.
  • Change the text instead of removing it: replace __return_empty_string with your own function that returns escaped HTML.

Gotchas

  • Product lists that add to the cart with AJAX never show this notice; they show a small View cart link next to the button instead. Hide it with a.added_to_cart { display: none; }.
  • Without any message, customers get no feedback after adding a product. Make sure a side cart or a cart count in the header shows the change. For a cart icon with a count, see Add WooCommerce Cart Icon on your website with Cart Item Count.

In the Scripts Organizer library Import it with one click from Scripts Organizer.

// newsletter

Three tested WordPress snippets a week

Blocks, security, performance, Tailwind, PHP and React. Copy, paste, ship. You’ll also get DPlugins product updates. No spam, and you can unsubscribe anytime.

// newsletter

Three tested WordPress snippets a week

Blocks, security, performance, Tailwind, PHP and React. Copy, paste, ship. You'll also get DPlugins product updates. No spam, and you can unsubscribe anytime.