【发布时间】:2020-02-07 22:16:59
【问题描述】:
我正在使用 sn-p 设置 WooCommerce 商店的最低订单价值。但是,如果使用优惠券,我会遇到一些问题。
例如,最小订单价值为 500,客户应用价值 500 的优惠券 - 这将给出小计 0,因此系统将不允许客户购买,因为小计小于最小订单价值.
因此,我正在尝试重写最低订单价值 sn-p,以便在应用优惠券时不会设置最小值。
在做了一些研究后,我发现我应该使用!empty($woocommerce->cart->applied_coupons)检查是否应用了优惠券。但是,这似乎不起作用。我错过了什么??
// MINIMUM ORDER AMOUNT
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) && !empty($woocommerce->cart->applied_coupons) ) {
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'
);
}
}
}
【问题讨论】:
标签: php wordpress plugins woocommerce hook-woocommerce