当您的购物车为空时,不能删除结账。在WooCommerce中通知(&Q) [英] Remove "Checkout is not available whilst your cart is empty." notice in WooCommerce

查看:6
本文介绍了当您的购物车为空时,不能删除结账。在WooCommerce中通知(&Q)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您的购物车为空时,我应该向functions.php添加哪些代码以删除&q;结账不可用。请注意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筛选器挂钩,如果消息匹配,则返回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 );

这篇关于当您的购物车为空时,不能删除结账。在WooCommerce中通知(&Q)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆