您可以通过不同的方式做到这一点:
1.覆盖notices.php模板:
您首先(如果尚未完成)将woocommercetemplates
文件夹复制到您的活动子主题或主题中,然后重命名它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; ?>
2.使用钩子:
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. 使用 CSS(类似的东西):
.woocommerce-cart .woocommerce-message {
display: none !important;
}
参考: