Solved

How to prevent buyers from adding multiple units of a product in the shopping cart.

eflouret
Tourist
13 0 3

Hello,

 

I sell digital downloads extended licenses, and there is no need for a buyer to buy more than one copy of a product. 

This isn't something that happens very often, but from time to time users start adding products to the cart and mistakenly add a second copy of a product.

 

How can I stop a user to add multiple copies of a product? Is there any app or should I custom code that feature?

 

Thanks

Accepted Solution (1)
Developer-G
Shopify Partner
3032 593 846

This is an accepted solution.

Yes Enrique, its possible.
It can be done in both ways using liquid or JS.
For liquid you can take idea from cart page code and for JS  you can use this

    $.getJSON("/cart.js", function(res) {
      console.log(res.items);
      for(var i = 0; i < res.items.length; i++) {
        //alert(res.items[i].id);
        if(res.items[i].id == $product_id) {
          // Your code
        }
      }
     }); 



- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on store Hire me.
- Email: guleriathakur43@gmail.com - Skype: navrocks1 ,
- Try GEMPAGES a great page builder
-Advance Search Filter

View solution in original post

Replies 6 (6)

Developer-G
Shopify Partner
3032 593 846

Hello,
You have to custom code the feature.
1) Remove quantity box from product and cart.

2) Check in product pages that is this product already in cart. 
Once you do it you can hide or disable button accordingly and if your theme is using ajax to add item in cart then you have go in that function and code it accordingly.

Thanks

- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on store Hire me.
- Email: guleriathakur43@gmail.com - Skype: navrocks1 ,
- Try GEMPAGES a great page builder
-Advance Search Filter
eflouret
Tourist
13 0 3

Awesome, thanks!

 

Besides removing the quantity counter in the shopping cart, the logic would be to add code to the product page, so when it loads, it checks the shopping cart and disables the buy button. 

 

Can that be done with Liquid, or should I use JS to check the shopping cart?

 

Enrique

 

 

Developer-G
Shopify Partner
3032 593 846

This is an accepted solution.

Yes Enrique, its possible.
It can be done in both ways using liquid or JS.
For liquid you can take idea from cart page code and for JS  you can use this

    $.getJSON("/cart.js", function(res) {
      console.log(res.items);
      for(var i = 0; i < res.items.length; i++) {
        //alert(res.items[i].id);
        if(res.items[i].id == $product_id) {
          // Your code
        }
      }
     }); 



- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on store Hire me.
- Email: guleriathakur43@gmail.com - Skype: navrocks1 ,
- Try GEMPAGES a great page builder
-Advance Search Filter
eflouret
Tourist
13 0 3

Excellent, that was really helpful

 

Thanks!

 

Enrique

m_sharrett
Visitor
1 0 0

For any others who (like me) deal in unique items, you can also modify cart.liquid under <input ... value ... min=“1”>.

Under value, replace item.quantity with 1 or whatever increment you want to set. And change min=“1” to max=“1” or whatever max you want to set. Also put in readonly after max=“1”. If readonly is omitted, users can still edit the box.

After the modifications, the line should look like this:

<input class=“quantity-selector” type=“number” name=“updates[]” id=“updates_{{ item.key }}” value=“{{ 1 }}” max=“1” readonly>

The above works for me under the Simple theme.

designrepo
Excursionist
48 0 4

Is it possible on dawn theme?? 

Please help me.