在 Woocommerce 中隐藏已添加到购物车的消息 [英] Hide Added to Cart message in Woocommerce
问题描述
我想从我的结帐页面顶部删除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 中隐藏已添加到购物车的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!