Skip to content

Instantly share code, notes, and snippets.

@lukecav
Created September 22, 2017 20:45
Show Gist options
  • Save lukecav/d189bf3aba7938f9ec0e7801d5313732 to your computer and use it in GitHub Desktop.
Save lukecav/d189bf3aba7938f9ec0e7801d5313732 to your computer and use it in GitHub Desktop.
Remove add to cart notices in WooCommerce
function remove_added_to_cart_notice()
{
$notices = WC()->session->get('wc_notices', array());
foreach( $notices['success'] as $key => &$notice){
if( strpos( $notice, 'has been added' ) !== false){
$added_to_cart_key = $key;
break;
}
}
unset( $notices['success'][$added_to_cart_key] );
WC()->session->set('wc_notices', $notices);
}
add_action('woocommerce_before_single_product','remove_added_to_cart_notice',1);
add_action('woocommerce_shortcode_before_product_cat_loop','remove_added_to_cart_notice',1);
add_action('woocommerce_before_shop_loop','remove_added_to_cart_notice',1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment