在Woocommerce购物车中设置最低小计金额 [英] Set a minimum subtotal amount in Woocommerce cart
本文介绍了在Woocommerce购物车中设置最低小计金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将最低订单金额设置为25美元.到目前为止,我已经找到了这段代码,如果未达到最低要求,这似乎可以阻止结帐,但是使用的小计是包括税款,我需要在总税款中排除该税款.
I'm trying to Set a minimum order amount of $25. So far i found this code, which seems to be fine for blocking the checkout if minimum is not reached, but the subtotal that it is using is with the tax included and I need to exclude the tax in the total.
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 25;
if ( WC()->cart->subtotal < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error'
);
}
}
}
推荐答案
您正在寻找
WC()->cart->subtotal_ex_tax
这将为您提供WooCommerce购物车小计,不含税
This will give you the WooCommerce Cart subtotal excluding tax
来源: https://docs.woocommerce.com/wc-apidocs/source-class-WC_Cart.html#48-49
这篇关于在Woocommerce购物车中设置最低小计金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文