我应该添加什么代码functions.php
删除“购物车为空时无法结账”。 Woocommerce 中的通知。
我在中找到了代码包括/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
过滤钩子,如果消息匹配,则返回 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 );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)