remove_action wc_empty_cart_message 无法在 WooCommerce 中使用
remove_action wc_empty_cart_message not working in WooCommerce
我想完全删除 wc_empty_cart_message
。我的网站没有购物车。当该项目从结帐中删除时,用户将被重定向到主页。但是当浏览到商店页面时,出现“您的购物车不可用,结帐为空”的消息,这是完全没有必要的。
我看过很多 questions/answers 关于如何将消息更改为其他内容的文章(我尝试了其中一些,但似乎也没有用)。
我试过这似乎是正确的做法,但出于某种原因,它并没有在我的网站上做出任何明显的改变。
remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
有什么方法可以检查哪个钩子正在从前端创建消息?或者我怎样才能看到是什么阻止了这个命令的执行?
要删除“您的购物车当前为空”消息,请使用:
function action_woocommerce_cart_is_empty() {
// Remove
remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
}
add_action( 'woocommerce_cart_is_empty', 'action_woocommerce_cart_is_empty', 9, 0 );
其中 remove_action
中的 add_action
具有较低的优先级编号 (9)
要删除“购物车为空时无法结帐”消息,请使用:
function filter_woocommerce_add_notice ( $message ) {
// Equal to (Must be exactly the same).
// If the message is displayed in another language, adjust where necessary!
if ( $message == 'Checkout is not available whilst your cart is empty.' ) {
return false;
}
return $message;
}
add_filter( 'woocommerce_add_notice', 'filter_woocommerce_add_notice', 10, 1 );
根据@7uc1f3r 的回答和我最近查看的一些其他教程中的信息,我发现这也可以解决问题:
add_filter( 'woocommerce_add_notice', '__return_null' );
我想完全删除 wc_empty_cart_message
。我的网站没有购物车。当该项目从结帐中删除时,用户将被重定向到主页。但是当浏览到商店页面时,出现“您的购物车不可用,结帐为空”的消息,这是完全没有必要的。
我看过很多 questions/answers 关于如何将消息更改为其他内容的文章(我尝试了其中一些,但似乎也没有用)。
我试过这似乎是正确的做法,但出于某种原因,它并没有在我的网站上做出任何明显的改变。
remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
有什么方法可以检查哪个钩子正在从前端创建消息?或者我怎样才能看到是什么阻止了这个命令的执行?
要删除“您的购物车当前为空”消息,请使用:
function action_woocommerce_cart_is_empty() {
// Remove
remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
}
add_action( 'woocommerce_cart_is_empty', 'action_woocommerce_cart_is_empty', 9, 0 );
其中 remove_action
中的 add_action
具有较低的优先级编号 (9)
要删除“购物车为空时无法结帐”消息,请使用:
function filter_woocommerce_add_notice ( $message ) {
// Equal to (Must be exactly the same).
// If the message is displayed in another language, adjust where necessary!
if ( $message == 'Checkout is not available whilst your cart is empty.' ) {
return false;
}
return $message;
}
add_filter( 'woocommerce_add_notice', 'filter_woocommerce_add_notice', 10, 1 );
根据@7uc1f3r 的回答和我最近查看的一些其他教程中的信息,我发现这也可以解决问题:
add_filter( 'woocommerce_add_notice', '__return_null' );