【问题标题】:Set a minimum undiscounted order amount in WooCommerce在 WooCommerce 中设置最低未打折订单金额
【发布时间】:2020-10-05 20:25:20
【问题描述】:

我使用“Minimum Order Amount”来要求最低订单金额。

如果我有一个 50 欧元的购物篮并且我应用了 10% 的折扣代码,我无法订购我的购物车,因为总价是 45 欧元。

但我想以 仅使用折扣码订购

【问题讨论】:

  • 好的。我不知道。谢谢

标签: php wordpress woocommerce cart discount


【解决方案1】:

更新:使用以下重新访问和压缩的代码,使用未打折的总数:

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 文件中。经过测试并且可以工作。

【讨论】:

  • 谢谢,但我尝试使用折扣码。总折扣是 40 欧元,它不起作用
  • @MichaelRobert 将$discount_total = WC()-&gt;cart-&gt;discount_total; 替换为$discount_total = WC()-&gt;cart-&gt;get_discount_total(); 有什么不同吗?
  • 我已经更新了我的答案……很奇怪,因为 $discount_total = WC()-&gt;cart-&gt;discount_total;$discount_total = WC()-&gt;cart-&gt;get_discount_total(); 都适用于不同的 WC 版本。
  • @LoicTheAztec 在调试时注意到该值保留为 0,我只使用 1 个版本的 WC,即最新的(4.2.0)。所以我无法将它与其他版本进行比较。我也无法立即解释其中的区别。
  • @7uc1f3r 我有自 2.4 版以来的所有主要版本进行测试:)
猜你喜欢
  • 2019-07-29
  • 1970-01-01
  • 1970-01-01
  • 2021-05-08
  • 2020-05-11
  • 2013-06-05
  • 2021-07-09
  • 1970-01-01
  • 2014-12-22
相关资源
最近更新 更多