【发布时间】:2020-10-05 20:25:20
【问题描述】:
我使用“Minimum Order Amount”来要求最低订单金额。
如果我有一个 50 欧元的购物篮并且我应用了 10% 的折扣代码,我无法订购我的购物车,因为总价是 45 欧元。
但我想以 仅使用折扣码订购
【问题讨论】:
-
好的。我不知道。谢谢
标签: php wordpress woocommerce cart discount
我使用“Minimum Order Amount”来要求最低订单金额。
如果我有一个 50 欧元的购物篮并且我应用了 10% 的折扣代码,我无法订购我的购物车,因为总价是 45 欧元。
但我想以 仅使用折扣码订购
【问题讨论】:
标签: php wordpress woocommerce cart discount
更新:使用以下重新访问和压缩的代码,使用未打折的总数:
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 文件中。经过测试并且可以工作。
【讨论】:
$discount_total = WC()->cart->discount_total; 替换为$discount_total = WC()->cart->get_discount_total(); 有什么不同吗?
$discount_total = WC()->cart->discount_total; 和 $discount_total = WC()->cart->get_discount_total(); 都适用于不同的 WC 版本。