最小订单价值停止在WooCommerce中使用促销代码

时间:2018-09-08 05:56:58

标签: php woocommerce

我的最低订单金额为10美元,我想给用户一个促销代码,并赠送30美元的信用额。但是,当我在购物车中输入促销代码时,小计显示$ 0,并且最小订单价值不允许订单完成。

对于最小订单价值,我在functions.php文件中使用了以下代码:

function wc_minimum_order_amount()
{
// Set this variable to specify a minimum order value
    $minimum = 10;

    if (WC()->cart->total < $minimum) {
        if (is_cart()) {
            wc_print_notice(
                sprintf(
                    'The minimum order value is %s Currently this order is %s',
                    wc_price($minimum),
                    wc_price(WC()->cart->total)
                ),
                'error'
            );
        } else {
            wc_add_notice(
                sprintf(
                    'The minimum order value is %s Currently this order is %s',
                    wc_price($minimum),
                    wc_price(WC()->cart->total)
                ),
                'error'
            );
        }
    }
}

1 个答案:

答案 0 :(得分:2)

我刚刚添加了if statement来检查是否应用了指定的优惠券,然后如果没有检查最小订单价值,请返回并正常进行订购

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 = 10;

    $coupon_code = 'test';  //Specific The Coupon Code to Check 
    if (in_array($coupon_code, WC()->cart->applied_coupons)) {
        return;
    }

    if (WC()->cart->total < $minimum) {
        if (is_cart()) {
            wc_print_notice(
                sprintf(
                    'The minimum order value is %s Currently this order is %s',
                    wc_price($minimum),
                    wc_price(WC()->cart->total)
                ),
                'error'
            );
        } else {
            wc_add_notice(
                sprintf(
                    'The minimum order value is %s Currently this order is %s',
                    wc_price($minimum),
                    wc_price(WC()->cart->total)
                ),
                'error'
            );
        }
    }
}

当然,该代码已经过测试,只需放在您的functions.php中,然后根据您的要求更改优惠券代码,就可以了。