我正在尝试设置最低25美元的订单金额。到目前为止,我发现这个代码,如果没有达到最低限度,似乎可以阻止结账,但是它使用的小计是含税,我需要在总数中排除税。
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'
);
}
}
}
答案 0 :(得分:1)
您正在寻找
WC()->cart->subtotal_ex_tax
这将为您提供不含税的WooCommerce Cart小计
来源:https://docs.woocommerce.com/wc-apidocs/source-class-WC_Cart.html#48-49