Select Sidearea

Populate the sidearea with useful widgets. It’s simple to add images, categories, latest post, social media icon links, tag clouds, and more.

How to set default product in cart

How to set default product in cart

Sometimes you would like to have a default product show up in your customer’s cart. For example, that is a freegift product or just a product you would like to sell.
For doing that, you can use my small script bellow. Remember to put it before the closed body tag and change the ID of variant product to valid ID. You can choose auto reloading page after product has been added or redirecting it to specified page (cart page) if you want.

<script> Shopify = Shopify || {};
    Shopify.cart = {{ cart | json }};
    if(Shopify.cart !=='undefined'
      && Shopify.cart.items.length === 0){
      jQuery.post('/cart/add.js', {
        quantity: 1,
        id: 1152084600,	//put your varian id here (should valid id, if not your site will be reload with nonstop loop)
        //window.location.reload(); //uncomment if you want to reload page
        window.location.href="cart?backurl="+window.location.href;  //if you want redirect to cart page
No Comments

Post a Comment



This site uses Akismet to reduce spam. Learn how your comment data is processed.