在 Woocommerce 中隐藏已添加到购物车消息

Hide Added to Cart message in Woocommerce

我想删除结帐页面顶部的 "xx product has been added to your cart" 消息。

我该怎么做?

有人(下面的link)提出了建议,但对我没有用。

Woocommerce 3+更新

挂钩 wc_add_to_cart_message 已弃用并由 wc_add_to_cart_message_html 取代。您可以使用以下(紧凑有效的方式):

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 之前,使用这个:

仅删除消息 (将其粘贴到活动子主题或主题中的 function.php 文件)。此函数将 return 一条空消息:

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 文件。

注意:wc_add_to_cart_message 替换已弃用的钩子 woocommerce_add_to_cart_message

(已更新)

CSS:删除结帐页面顶部的消息框 (将此 css 规则添加到 style.css 文件位于您活跃的子主题或主题中):

.woocommerce-checkout .woocommerce .woocommerce-message {
    display:none !important;
}

您必须使用此代码才能隐藏它

add_filter( 'wc_add_to_cart_message_html', '__return_false' );

您可以在此处找到更多信息hide added to your cart