I'm trying to set up a coupon on my client's WooCommerce site so that a percentage discount applies if the total cart is below a cap amount or a fixed amount is equal or greater than the cap amount.
Let's say that the cap for the cart total is 200. If the cart total is below this cap, 10% discount is applied. But if the cart total is 200 or greater, then the fixed amount of 20 is applied as the discount.
For example:
- My cart total is 190. Since this is less than the cap of 200, the discount amount is computed as 10%, which is 19 is applied
- My cart total is 210. Since this is greater than the cap of 200, then the fixed amount of 20 is applied.
How do I set my WooCommerce to apply a percentage discount or fixed cart depending on the total?
Ok so I finally figure out how to use this code so that it only triggers when the coupon is added. I also added a script to notify the buyer that the coupon discount limit has been reached
}
You can use a custom function hooked in
woocommerce_before_calculate_totals
action hook where you will define 2 coupons codes:The code:
Code goes in function.php file of the active child theme (or active theme).
Tested and works.
OR you can also use a negative fee (so a discount) instead of coupons this way:
Code goes in function.php file of the active child theme (or active theme).
Tested and works.