actions and filters. On my WooCommerce site I get the following message when I remove a product from the shopping cart:
"<product name>" removed. Undo?
Looking over WooCommerce source code I have found a conditional statement in class-wc-form-header.php
as part of the function update_cart_action()
:
$removed_notice .= ' <a href="' . esc_url( WC()->cart->get_undo_url( $cart_item_key ) ) . '">' . __( 'Undo?', 'woocommerce' ) . '</a>';
But I can’t find the way to use it for eliminate this notice. I have try css solutions but it didn’t work:
PS: that may not be the code snippet that is bothering me, but its the only one I have found that seems to make sense.
How can I remove this bothering notice?
Thanks.
Advertisement
Answer
You can do that in different ways:
1. Overriding the notices.php template:
You have first (if not done yet) to copy woocommerce templates
folder inside your active child theme or theme, then rename it woocommerce
. Then open/edit notices/notices.php
and try to replace the code:
<?php /** * Show messages * ... Blabla ... / ... blabla ... * @version 1.6.4 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } if ( ! $messages ){ return; } ?> <?php foreach ( $messages as $message ) : // Change your template code from here if ( strpos( $message, 'removed' ) === false ) : ?> <div class="woocommerce-info"><?php echo wp_kses_post( $message ); ?></div> <?php endif; endforeach; ?>
2. Using hooks:
function remove_added_to_cart_notice() { $notices = WC()->session->get('wc_notices', array()); foreach( $notices['notices'] as $key => &$notice){ if( strpos( $notice, 'removed' ) !== false){ $added_to_cart_key = $key; break; } } unset( $notices['notices'][$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);
3. Using CSS (with something like):
.woocommerce-cart .woocommerce-message { display: none !important; }
References: