Automatically add a product to every Shopify cart before your customers check out. Great for gifts, packaging materials, or any other line items you need on every order.
Add the following to your Shopify theme:
<script src='https://ca-la.github.io/shopify-add-to-cart/add.js'></script>
<script>window.ShopifyAddToCart.autoAdd('MY_VARIANT_ID');</script>
— Replace MY_VARIANT_ID
with the ID of the variant for the item you'd like to add to each cart.
<script>window.ShopifyAddToCart.hideCartItems('MY_VARIANT_ID');</script>
- Create a Shopify product to represent the item you'd like to add to every cart (e.g. "your free gift").
- Take the URL of this product in your shopify admin dashboard, and add
/variants.json?fields=id
on the end.- e.g. My product URL is
https://mystore.myshopify.com/admin/products/1434053640247
, so I want to go tohttps://mystore.myshopify.com/admin/products/1434053640247/variants.json?fields=id
- e.g. My product URL is
- Grab the ID number that appears on the screen (e.g.
12867262677047
). That's your "variant ID" for this gift item.
- In the sidebar of your admin dashboard, click "Sales Channels" -> "Online Store" -> "Themes". From the "Actions" dropdown, select "Edit Code".
- Find the
theme.liquid
file, scroll to the bottom, and paste the code from before, right before the closing</body>
tag. - Hit Save, and enjoy!
Edit add.ts
. Uses Prettier. Run npm run format
before commiting.