Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › How to create coupon with multiple discount rules › Reply To: How to create coupon with multiple discount rules

#21570
Soft79
Keymaster

That may work with a similar script. Create a 5% discount coupon for items in category A and replace the previous snippet with the following snippet.

Replace COUPON_CODE_B with the category B coupon code and replace COUPON_COUDE_A with the category A coupon code.


add_filter(
    'woocommerce_coupon_get_amount', 
    function ($amount, $coupon) {
        if ($coupon->get_code() !== 'COUPON_CODE_B') return $amount;
        if (is_admin() && !defined('DOING_AJAX')) return $amount;
        $cart_total = WC()->cart->get_subtotal();
        if ($cart_total >= 5000) return 20;
        if ($cart_total >= 4000) return 20;
        if ($cart_total >= 3000) return 15;
        if ($cart_total >= 2000) return 10;
        if ($cart_total >= 1000) return 5;
        return 0;
    }, 10, 2
);
add_filter(
    'woocommerce_coupon_get_amount',
    function ($amount, $coupon) {
        if ($coupon->get_code() !== 'COUPON_CODE_A') return $amount;
        if (is_admin() && !defined('DOING_AJAX')) return $amount;
        if (!function_exists('WJECF')) return $amount;
        $n_items = WJECF()->get_quantity_of_matching_products();
        if ($n_items >= 6) return 15;
        if ($n_items >= 4) return 10;
        if ($n_items >= 2) return 5;
        return 0;
    }, 10, 2
);