我使用“Minimum Order Amount”来要求最低订购量。
如果我有一篮子 50 欧元的商品并且我应用了 10% 的折扣代码,我无法订购我的购物车,因为总计 45 欧元。
但我想订购 < 50 欧元 ONLY with a discount code
最佳答案
更新:使用以下重新访问和压缩的代码,使用未折扣的总数:
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->get_discount_total(); // updated thanks to 7uc1f3r
$maximized_total = $total + $discount_total;
if ( $maximized_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( $maximized_total ),
wc_price( $minimum )
);
if( is_cart() ) {
wc_print_notice( $notice , 'error' );
} else {
wc_add_notice( $notice , 'error' );
}
}
}
代码进入事件子主题(或事件主题)的 functions.php 文件。经过测试并有效。
关于php - 在 WooCommerce 中设置最低未折扣订单金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62404924/