删除 WooCommerce 中的 "Checkout is not available whilst your cart is empty." 通知
Remove "Checkout is not available whilst your cart is empty." notice in WooCommerce
我应该将什么代码添加到 functions.php
以删除“购物车为空时无法结帐”。在 Woocommerce 中通知。
我在 includes/wc-template-functions.php 中找到了负责显示此消息的代码。
// When on the checkout with an empty cart, redirect to cart page.
if ( is_page( wc_get_page_id( 'checkout' ) ) && wc_get_page_id( 'checkout' ) !== wc_get_page_id( 'cart' ) && WC()->cart->is_empty() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) && ! is_customize_preview() && apply_filters( 'woocommerce_checkout_redirect_empty_cart', true ) ) {
wc_add_notice( __( 'Checkout is not available whilst your cart is empty.', 'woocommerce' ), 'notice' );
wp_safe_redirect( wc_get_cart_url() );
exit;
}
覆盖核心文件不是一个选项,有什么建议吗?
您可以使用 woocommerce_checkout_redirect_empty_cart
过滤器挂钩。由于仅当此条件为真时才会显示消息
add_filter( 'woocommerce_checkout_redirect_empty_cart', '__return_false' );
另一种选择是使用 woocommerce_add_notice
过滤器钩子,如果消息匹配,return false
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 );
我应该将什么代码添加到 functions.php
以删除“购物车为空时无法结帐”。在 Woocommerce 中通知。
我在 includes/wc-template-functions.php 中找到了负责显示此消息的代码。
// When on the checkout with an empty cart, redirect to cart page.
if ( is_page( wc_get_page_id( 'checkout' ) ) && wc_get_page_id( 'checkout' ) !== wc_get_page_id( 'cart' ) && WC()->cart->is_empty() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) && ! is_customize_preview() && apply_filters( 'woocommerce_checkout_redirect_empty_cart', true ) ) {
wc_add_notice( __( 'Checkout is not available whilst your cart is empty.', 'woocommerce' ), 'notice' );
wp_safe_redirect( wc_get_cart_url() );
exit;
}
覆盖核心文件不是一个选项,有什么建议吗?
您可以使用 woocommerce_checkout_redirect_empty_cart
过滤器挂钩。由于仅当此条件为真时才会显示消息
add_filter( 'woocommerce_checkout_redirect_empty_cart', '__return_false' );
另一种选择是使用 woocommerce_add_notice
过滤器钩子,如果消息匹配,return false
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 );