You can set up your cart to automatically include a product as a gift. The product is added automatically when any other item is added to an empty cart.
To add a product to your cart automatically:
- Grab the handle of your add-on product
- Create a new snippet
- Include the new snippet in your cart template
This customization is not possible if your cart uses Ajax. If you use any of the following themes: Solo, Pop, React, Classic, Supply or Brooklyn, by Shopify, you must disable Ajax on your Customize theme page. In the Cart page section, set "Cart type" to "Page".
Grab the handle of your add-on product
On the product page, under Search engine listing preview, click the Edit website SEO link.
The product handle is shown under 'URL and handle':
In the above example, the handle is surprise-gift-35-value
. You will need that handle later.
Create a new code snippet
-
Go to the Edit HTML/CSS page.
-
Click the Snippets folder, then click Add a new snippet.
-
Give your snippet the name
cart-add-on
and click Create snippet. Your new code snippet file will automatically open in the online code editor. -
Copy the code from this project's cart-add-on.liquid file into your snippet.
-
Look for the following text:
put-your-product-handle-here
Replace that text with the product handle you grabbed before.
-
Click Save to save your new code snippet.
Include the new snippet in your cart.liquid template
Now you must edit your cart.liquid template to include your new code snippet.
-
Under the Templates folder, locate and click on cart.liquid to open it in the online code editor.
-
Copy+paste the below code at the very bottom of your cart.liquid snippet:
{% include 'cart-add-on' %}
-
Click save.