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

Solved
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

0 Likes
Guleria
Shopify Partner
1476 304 421

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

Want to modify or custom changes on store hire me.
Email: guleriathakur43@gmail.com, Skype: navrocks1
If helpful then please Like and Accept Solution.
0 Likes
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

 

 

0 Likes
Guleria
Shopify Partner
1476 304 421

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
        }
      }
     }); 



Want to modify or custom changes on store hire me.
Email: guleriathakur43@gmail.com, Skype: navrocks1
If helpful then please Like and Accept Solution.
eflouret
Tourist
13 0 3

Excellent, that was really helpful

 

Thanks!

 

Enrique

0 Likes
m_sharrett
New Member
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.

0 Likes