0

After reading this splendid code (Add free product when coupon is applied in WooCommerce) by @7uc1f3r, how do you set up your coupon when you create it, so the solution works?

When testing mine, it does only apply the discount type I entered for the coupon (-0%), but does not add a free product to cart.

aurelb
  • 1
  • 3
  • The coupon setup is not applicable. As long as the coupon code is in the `$coupon_codes` array. Furthermore, your question only contains a description, but not a step-by-step [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) that makes 'the problem' (if any) really clear. So please (re)take the [tour](https://stackoverflow.com/tour) - _"This site is all about getting answers. It's not a discussion forum. There's no chit-chat."_ - and read through [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – 7uc1f3r May 11 '22 at 19:09
  • Sorry, I will rephrase my "comment" into a question. I copied/pasted your code in functions.php and had the following error "The coupon does not exist". So I created the coupon and did not have any product added to the cart when applying the coupon to the cart. Question: what to do to make it work? Many thanks in advance for your answer. – aurelb May 17 '22 at 14:15
  • _"Question: what to do to make it work?"_ - When I posted the answer it worked as the inquirer wanted and it still does. So no idea.. you may need to [debug](https://stackoverflow.com/questions/61740111/how-to-debug-in-woocommerce-3) as this problem generally doesn't occur – 7uc1f3r May 17 '22 at 16:54

0 Answers0