问题描述
我想从结帐页面顶部删除"xx产品已添加到您的购物车" 消息.
I want to remove the "xx product has been added to your cart" message from the top of my checkout page.
我该怎么做?
有人建议(下面的链接),但对我来说不起作用.
There was a suggestion by someone (link below), but it didn't work for me.
删除/隐藏Woocommerce已添加到购物车消息中,但保留/显示优惠券已应用消息
推荐答案
Woocommerce 3+的更新
不建议使用钩子wc_add_to_cart_message
,并由wc_add_to_cart_message_html
代替.您可以使用以下方法(紧凑有效的方法):
The hook wc_add_to_cart_message
is deprecated and replaced by wc_add_to_cart_message_html
. You can use the following (compact effective way):
add_filter( 'wc_add_to_cart_message_html', '__return_false' );
或正常方式:
add_filter( 'wc_add_to_cart_message_html', 'empty_wc_add_to_cart_message');
function empty_wc_add_to_cart_message( $message, $products ) {
return '';
};
在Woocommerce 3之前,请使用此功能:
Before Woocommerce 3, use this:
仅删除消息(将其粘贴到当前子主题或主题内的function.php
文件中).此函数将返回空消息:
Removing only the message (pasting it to your function.php
file inside your active child theme or theme). This function will return an empty message:
add_filter( 'wc_add_to_cart_message', 'empty_wc_add_to_cart_message', 10, 2 );
function empty_wc_add_to_cart_message( $message, $product_id ) {
return '';
};
代码进入您的活动子主题(或活动主题)的function.php文件中.
Code goes in function.php file of your active child theme (or active theme).
注意:wc_add_to_cart_message
替换不赞成使用的钩子woocommerce_add_to_cart_message
.
Note: wc_add_to_cart_message
replace deprecated hook woocommerce_add_to_cart_message
.
(已更新)
CSS:在结帐页面上删除顶部消息框 (将此CSS规则添加到活动子主题或主题内的style.css
文件中):
CSS: Removing top message box on checkout page (add this css rule to the style.css
file located inside your active child theme or theme):
.woocommerce-checkout .woocommerce .woocommerce-message {
display:none !important;
}
这篇关于在Woocommerce中隐藏添加到购物车消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!