在WooCommerce中设置最低未打折订单金额

时间:2020-06-16 09:08:21

标签: php wordpress woocommerce cart discount

我使用“ https://developer.mozilla.org/ru/docs/Web/API/Event/preventDefault”来要求最低订购量。

如果我有50欧元的购物篮,并使用10%的折扣代码,则我无法订购购物车,因为总金额为45欧元。

但是我只想订购带有折扣码的 <50欧元

1 个答案:

答案 0 :(得分:3)

已更新:使用以下重新审阅并压缩的代码,该代码使用未折现的总额:

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

相关问题