0

Note: In looking for an answer to my question I came across this post but it is NOT duplicate: Remove add to cart notice and change "add to cart" button in Woocommerce the answer there gives the option to remove the notice from the entire site. I want to remove it only from the cart page and I don't want to do it with CSS.


I use external links to my site to send people directly to the shopping cart with the item already added to the cart. When doing so, the "added-to-cart notification" shows up on the cart page which I do not want.

I found this code which removes the added-to-cart notification: add_filter( 'wc_add_to_cart_message_html', '__return_false' ); but it removes the notification from all pages of my site which is not what I want.

To be more specific, I want the added-to-cart notification to show on every product archive page and nowhere else.

I tried to add a filter but it doesn't work the way I would expect it to, I tried the following two ways (and tested it with various pages to see if I could make anything work but it seems my general syntax is off because I Can't get it to do anything...

function hide_cart_notes() { 
    if ( ! is_archive() ) { 
        add_filter( 'wc_add_to_cart_message_html', '__return_false' );
    }
}
add_action( 'woocommerce', 'hide_cart_notes' );
function hide_cart_notes() { 
    if ( is_archive() ) { 
        return; 
    }
add_filter( 'wc_add_to_cart_message_html', '__return_false' );

}
add_action( 'woocommerce', 'hide_cart_notes' );
J.K.
  • 167
  • 1
  • 10

1 Answers1

0

when woocommerce hook starts? where it's docs? does it run at all? these question should be answered before.

i know that WordPress parses query at parse_query hook, so i would try this

add_action('parse_query', function() {
  if (!is_archive()) {
    add_filter( 'wc_add_to_cart_message_html', '__return_false' );
  }
});

because is_shop(), is_archive(), is_* need query to be parsed first.

Michael Quad
  • 149
  • 6
  • Thanks. I tried this but it didn't work. The message still appears on the cart page and other pages. – J.K. Jun 22 '21 at 17:37
  • then add a filter that returns something and check if it the message changes.. maybe you have a custom theme/plugin that overrides standard templates – Michael Quad Jun 22 '21 at 19:39