Skip to content

carolineschnapp/add-product-to-cart-automatically

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Add a product to the cart automatically

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:

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':

Alt text

In the above example, the handle is surprise-gift-35-value. You will need that handle later.

Create a new code snippet

  1. Go to the Edit HTML/CSS page.

  2. Click the Snippets folder, then click Add a new snippet.

  3. 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.

  4. Copy the code from this project's cart-add-on.liquid file into your snippet.

  5. Look for the following text:

    put-your-product-handle-here

    Replace that text with the product handle you grabbed before.

  6. 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.

  1. Under the Templates folder, locate and click on cart.liquid to open it in the online code editor.

  2. Copy+paste the below code at the very bottom of your cart.liquid snippet:

    {% include 'cart-add-on' %}

  3. Click save.

About

Add a product to the cart automatically in Shopify

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages