1
votes

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?

5

5 Answers

0
votes

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;
}`
0
votes

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 );
    }
}
0
votes

This works for me.

add_filter( 'wc_add_to_cart_message_html', '__return_null' );

-1
votes

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

add_filter( 'woocommerce_cart_item_removed_title', '__return_null' );

-1
votes

Place this code to functions.php

add_filter( 'wc_add_to_cart_message_html', '__return_false' );