Liquid, JavaScript, themes, sales channels
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
Solved! Go to the solution
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 } } });
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
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
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 } } });
Excellent, that was really helpful
Thanks!
Enrique
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.
Is it possible on dawn theme??
Please help me.
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024