We want to automagically add a free product to the customers cart when they purchase a certain product(s).
Note: This code will likely need to be adapted to suit your theme, however it should be enough to discribe the concept.
Add the free product
-
Define the free product and which products can add it. We create some theme setting that allow us to pick the free product and a collection of products that can add it. e.g.
settings.free-product
andsettings.free-product-collection
-
Collect the free product and hand it off to the JS. Get the current product, if we have one. Set up some conditions for adding. This is done inside the
<head>
. See theme.liquid. -
Capture the form submit and add the current and free products to the cart. See product.js
Remove the free product To do
Would i just add create a new file called product.js inside my theme assets folder? Thanks for this so much, shopify's docs are not the best.