1

I need to remove the woocommerce cart message that is displayed when you remove a product from the cart ("... was removed from your cart. Undo?")

I tried the code found here: WooCommerce - unset "<product> removed notice…" on cart page

but it did not work, the message is still displayed. Does anyone know how to hide it?

mark
  • 69
  • 2
  • 8

5 Answers5

0

You can do this with overriding notices in your themes functions.php file using some hooks. Please try this code and check whether it works.

add_filter( 'woocommerce_cart_item_removed_title', 'removed_from_cart_title', 12, 2);
function removed_from_cart_title( $message, $cart_item ) {
    $product = wc_get_product( $cart_item['product_id'] );

    if( $product )
    $message = sprintf( __(''), $product->get_name() );
    return $message;
    }
add_filter('gettext', 'cart_undo_translation', 35, 3 );
function cart_undo_translation( $translation, $text, $domain ) {

    if( $text === 'Undo?' ) {
    $translation =  __( '', $domain );
    }
return $translation;
}`
Brijesh Dhanani
  • 856
  • 4
  • 12
0

I have tried this and working fine for me. May become helpful to you. Add this code in functions.php in child theme :

add_action( 'template_redirect', 'null_removed_cart_item_message'  );
function null_removed_cart_item_message() {
    // Only on cart page
    if( ! is_cart() ) return;
    // Get the WC notices array stored in WC_Session
    $wc_notices = (array) WC()->session->get( 'wc_notices' );
    $found      = false; // Initializing
    // Check that we have at least one "success" notice type
    if( isset($wc_notices['success']) && sizeof($wc_notices['success']) ) {
        // Loop through "success" notices type
        foreach( $wc_notices['success'] as $key => $wc_notice ) {
            // Remove notices that contain the word "removed" from the array
            if ( strpos($wc_notice, 'removed') !== false ) {
                unset($wc_notices['success']);
                $found = true;
            }
        }
    }
    if( $found ) {
        // Set back the notices array to WC_Session
        WC()->session->set( 'wc_notices', $wc_notices );
    }
}
IncipientInfo
  • 523
  • 3
  • 10
  • I am confused. I tried all of the codes on a fresh WP installment and the Storefront theme, which is by Woocommerce. None of them work, how can they work for anyone else? – mark Jul 01 '19 at 17:45
  • @mark can you please elaborate where you are using this code. In which file? – IncipientInfo Jul 02 '19 at 05:18
  • I am adding the code to my child theme's function.php – mark Jul 02 '19 at 15:24
0

This works for me.

add_filter( 'wc_add_to_cart_message_html', '__return_null' );

garth
  • 154
  • 9
-1

Try to add this line of code in your theme's function.php file.

add_filter( 'woocommerce_cart_item_removed_title', '__return_null' );

Akhilesh
  • 927
  • 1
  • 6
  • 21
-1

Place this code to functions.php

add_filter( 'wc_add_to_cart_message_html', '__return_false' );
albert_rar
  • 19
  • 1
  • 3