I have a client who wants to add a coupon for WordPress/WooCommerce checkout. Normally I would just go to WooCommerce > Coupons and create the coupon.
However, they want one coupon code to give a product discount to TWO separate products. Products in this case are admission tickets.
- coupon code name is = “COUPON1”
- “PRODUCT A” is $15.95 on weekdays (product ID = 2846)
- “PRODUCT A” is $17.95 on weekends (product ID = 2848)
- “PRODUCT B” is $10.95 on weekdays (product ID = 2847)
- “PRODUCT B” is $12.95 on weekends (product ID = 2849)
- PRODUCT A discount is $11.95 for both weekday and weekend tickets
- PRODUCT B discount is $8.95 for both weekday and weekend tickets
Workflow:
- User adds 1 ticket for PRODUCT A to cart
- User adds 1 ticket for PRODUCT B to cart
- User enters coupon COUPON1 to discount field
- WordPress hook notices these products in cart by their ID and notices that the coupon COUPON1 has been applied
- WordPress creates the discounted prices for PRODUCTS A and B
- Subtotal now shows $11.95 + $8.95 = $20.90
I can create one coupon code for the $15.95 weekend and weekday tickets but it can’t be applied to the second product (PRODUCT B).
The discount to $11.95 should be applied IF the coupon is applied and IF any of the product IDs 2846 or 2848 are in the cart.
The discount to $8.95 should be applied IF the coupon is applied and IF any of the product IDs 2847 or 2849 are in the cart.
I figured there is probably a webhook that can be written that will do this for me.
Thanks in advance.
2
Answers
Here is what I did, in case anybody else wants to do this in the future:
I don’t think this can be done with one coupon code. At first I thought you need one coupon code for weekdays and weekends to change automatically, but having to different discounts for two different products is impossible.
What you can do, is adding the a second coupon dynamically on the fly. Have a “secret” coupon on the back-end that will control only over the Product B (using the coupon limitations – choose Product B only to be affected).
Then add and adjust the coupon dynamically each time the Product B is in cart:
I noticed you are using few product IDs. This code can give you a solution if you modify it for your needs.