Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Problem with quantity limit to add to cart

Problem with quantity limit to add to cart

Antonio87
Visitor
2 0 0

Good morning,
I have a problem with the theme

There is no quantity lock present in inventory

I would like the number of available products to appear on the product page and that it is not possible to add quantities to the cart that exceed the available quantities.

I would also like it to be possible for this limit not to be bypassed during checkout and for a quantity limit message to always appear

I'll show you the code I have and if anyone can help me with this modification

 

{%- if product.variants.size == 0 -%}
{%- assign id = ''  -%}
{%- assign checked = ''  -%}
{%- else -%}
{%- for variant in product.variants -%}
{%- if variant.available -%}
{%- assign id = variant.id  -%}
{%- assign checked = 'checked'  -%}
{% break %}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
 
<div class="group_products-item {%- if id == '' -%}disable{%- endif -%}">
  
  <input class="group_product-item" type="checkbox" value="{{id}}" {{checked}}>
  <div>
    <img width="auto" height="auto" src="{{product.featured_media | img_url: '200x' }}" alt="{{ product.title | escape }}">
    {% render 'quickview-button', handle: product.handle %}
  </div>
  <a href="{{product.handle}}">{{product.title}}</a>
</div>

 

Thank you

Reply 1 (1)

JimJong
New Member
56 0 0

Yes it is possible to limit the quantity to add to cart by using the Cart Lock https://apps.shopify.com/cart-lock app easily. Follow the steps below:

 

  1. Open the app and click on the "Add a new rule" button.
  2. Click "Add a new condition" and select the "Products" then add your products.
  3. Click "Add a new condition" again and select the "Single item quantity" then put 5 or any number in the "Block if more than" field.
  4. In the "Error message" field, add an appropriate message which will be displayed in the checkout page.
  5. Select "All" from the "Match conditions" field.
  6. Save the rule.

limitcart.png

 

Now your customers can not add more than quantity 5.