Answer the question
In order to leave comments, you need to log in
How to get rid of the notification "Product removed. cancel?"?
Hello! The online store has the latest 3.0.5 version of woocommerce and wordpress 4.7, respectively, with the standard storefront theme. I make all changes through a child theme. My question is 1 in 1 like here - how to get rid of all notifications coming from the basket, in particular when removing an item from the basket?
I do everything according to the recommendations: I
overwrite the notice.php file along the path storefront-child/woocommerce/notices/notices.php
<?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; ?>
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);
// Removes Product Successfully Added to Cart
add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
echo '<style>.woocommerce-message {display: none !important;}</style>';
wc_clear_notices();
}
//Remove Message:
add_action( 'init', 'remove_notices' );
function remove_notices() {
remove_action( 'woocommerce_before_shop_loop', 'wc_print_notices', 10 ); /*Archive Product*/
remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 ); /*Single Product*/
remove_action( 'storefront_content_top', 'storefront_shop_messages', 1 );
}
.woocommerce-message {
display: none !important;
}
$removed_notice .= ' <a href="' . esc_url( WC()->cart->get_undo_url( $cart_item_key ) ) . '">' . __( 'Undo?', 'woocommerce' ) . '</a>';
wc_add_notice( $removed_notice );
Answer the question
In order to leave comments, you need to log in
It is necessary to overwrite not the notice.php file, but success.php (the code from the first block). You need to hide the woocommerce-message block, not woocommerce-info.
And also in Cyrillic in $message, if the Russified version is used, i.e. the removed line will not be found.
<?php foreach ( $messages as $message ) :
if( strpos($message, 'удален') === false ): ?>
<div class="woocommerce-message" role="alert">
<?php
echo wc_kses_notice( $message );
?>
</div>
<?php endif;
endforeach; ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question