Remove “product removed. Undo” notice from the shop page

When your site visitor removes an item from their cart, the page refreshes and they get a notice like this one:

Undo product remove notice

You may not want to show this notification to your visitors. Unfortunately, there’s no easy filter that can get rid of this notice. Lucky for us, there is another way:

function sw_delete_remove_product_notice(){
	$notices = WC()->session->get( 'wc_notices', array() );
	if(isset($notices['success'])){
		for($i = 0; $i < count($notices['success']); $i++){
			if (strpos($notices['success'][$i], __('removed','woocommerce')) !== false) {
				array_splice($notices['success'],$i,1);
			}
		}
		WC()->session->set( 'wc_notices', $notices['success'] );
	}
}

add_action( 'woocommerce_before_shop_loop', 'sw_delete_remove_product_notice', 5 );

All this does is lookup the current ‘success’ notices and delete the notice with ‘removed’ in the sentence. With that in mind, it’s not failsafe but should do the trick as it’s unlikely that there will be 2 different success-notices with the word ‘removed’ in them.

If you want to remove it on single product pages or category pages, you can use these actions as well

add_action( 'woocommerce_shortcode_before_product_cat_loop', 'sw_delete_remove_product_notice', 5 );
add_action( 'woocommerce_before_single_product', 'sw_delete_remove_product_notice', 5 );