Hi all, part of the functionality of the store we're building is the feature to add (free) specific products to the cart based on a discount code they enter at the checkout page. I can't seem to find a reliable way to do this, but maybe some of you can point me in the right direction or help me get started.
Appreciate any advice you all can offer, cheers!
Solved! Go to the solution
This is an accepted solution.
Basically, when the apply discount button is clicked, it iterates through a list of discount codes prepared with corresponding free gifts. If the text in the discount code field matches one of the discount codes in the list, it calls POST /cart/update.js with the variant id of the product and quantity set to 1 (so entering the same code multiple times won't duplicate).
Removing the product was simply iterating each discount tag and watching their button clicks, then matching the discount text with the list again and removing the associated product ID from the cart.