我使用代码要求最低订购量。例如:50€。
如果我有50欧元的购物篮,并且我应用10%的折扣代码,则我无法订购我的购物车,因为总金额为45欧元。
但是我想订购
/**
* Set a minimum order amount for checkout
*/
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 = 50;
if ( WC()->cart->total < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order ' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
}
}
}
使用以下重新访问的代码,该代码使用未折现的总计:
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 = 50;
$total = WC()->cart->total
$discount_total = WC()->cart->discount_total;
$undiscounted_total = $total + $discount_total;
if ( $undiscounted_total < $minimum ) {
$notice = sprintf( __('Your current order total is %s — you must have an order with a minimum of %s to place your order '),
wc_price( $undiscounted_total ),
wc_price( $minimum )
);
if( is_cart() ) {
wc_print_notice( $notice , 'error' );
} else {
wc_add_notice( $notice , 'error' );
}
}
}
它应该起作用。