在 Woocommerce 购物车中设置最小小计金额
Set a minimum subtotal amount in Woocommerce cart
我正在尝试将最低订购量设置为 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'
);
}
}
}
您正在寻找
WC()->cart->subtotal_ex_tax
这将为您提供不含税的 WooCommerce 购物车小计
来源:https://docs.woocommerce.com/wc-apidocs/source-class-WC_Cart.html#48-49
我正在尝试将最低订购量设置为 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'
);
}
}
}
您正在寻找
WC()->cart->subtotal_ex_tax
这将为您提供不含税的 WooCommerce 购物车小计
来源:https://docs.woocommerce.com/wc-apidocs/source-class-WC_Cart.html#48-49