Last active
April 10, 2024 09:31
-
-
Save Paulsky/bb8d28de7fb8fbf61648aee49472ce8b to your computer and use it in GitHub Desktop.
Remove Woocommerce 'Added to cart' notice when the product is removed from the cart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('woocommerce_remove_cart_item', 'remove_added_to_cart_message_for_product', 10, 2); | |
function remove_added_to_cart_message_for_product($cart_item_key, $cart) | |
{ | |
$product_id = $cart->removed_cart_contents[$cart_item_key]['product_id']; | |
$product = wc_get_product($product_id); | |
if (!$product) { | |
return; | |
} | |
$all_notices = wc_get_notices(); | |
if (empty($all_notices['success'])) { | |
return; | |
} | |
$product_name = get_the_title($product_id); | |
foreach ($all_notices['success'] as $index => $notice) { | |
if (strpos($notice['notice'], $product_name) !== false) { | |
unset($all_notices['success'][$index]); | |
} | |
} | |
$all_notices['success'] = array_values($all_notices['success']); | |
wc_set_notices($all_notices); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment