How to set a minimum quantity on a single product?

How to set a minimum quantity on a single product?

bcomst
Excursionist
12 0 6

Hi Everyone, 

I am trying to set a minimum quantity to a specific product that we offer.  All other products are still fine at 1, but a particular product type needs to be a minimum of 4.  How would I change this to start the order at 4 but allow the customer to change the quantity to anything equal to or higher?

 

I've looked through other similar requests and have looked around the product-template.liquid code but I don't think that's what I want since it seems to change the minimum of everything instead of a single product.

 

Further note, this product changes every few months for a new promotion and art, so it would be exceptionally useful if I could somehow tie this minimum restriction to a given tag.  So any time I add the tag MIN4, it applies the minimum 4 rule.

 

Is that possible?    Thanks!

Replies 10 (10)

speedboostr
Trailblazer
136 20 26

@bcomst  this is possible with a little custom coding.

 

Here's how I would approach it:

1) Add the MIN4 tag to the products you want minimum

 

2) In the product form file (product-form.liquid, or product.liquid, etc whatever has the quantity / add to cart button), create a script that runs if that tag is present, something like this:

 

 

<p id="error-msg" style="display: none; color: red;">This product requires a quantity of 4 minimum.</p>

{% if product.tags contains "MIN4" %}
<script>
// Example to set a minimum on the input box
let qty = document.querySelector("#quantity");
qty.min = 4;

// I would add a backup, for example if you're using a select box or if the user's browser ignores the minimum attribute
document.addEventListener("click", (event) => {
  let qtySelected = document.querySelector.value;

  if (event.target.innerText.indexOf("Add to Cart") >= 0 && qtySelected < 4) {
    // Reveal an error message
    document.querySelector("#error-msg").display = block;
  }
});

</script>
{% endif %}

 

 

 

3) If you're showing an error message, you could also add some code to clear the message when quantity of 4 is selected (set an event listener on the quantity box).

 

The exact code will depend on your product page setup, but that code above will help you get started, experiment with that and swap out what you need.

 

If you prefer to have a professional developer handle it for you, feel free to reach out to my team at speedboostr.com/contact - our developers work on Shopify sites every day to do customizations like this.

Creator of Theme Scientist (A/B testing app and theme scheduler). Creator of Shopify Analyzer (1st performance analysis tool for Shopify, free for the community). Founder of Speed Boostr (Shopify optimization experts + app developers). More apps from our team: Tip Jar (add a tip button), File Optimizer (optimize CSS, JS, Liquid).
KikyChen
Visitor
1 0 0

I've tried your code and found that if the product contains several options, the min limitation will fail when the option change.

 

So I made some update of the code, which set the default quantity of the variant selection to the minimum requirement, and the limitation can be applied to all the variant.

 

It should be pasted to the main-product.liquid, and find the quantity section:

<span class="input-amount">
<label for="quantity" class="hidden">{{ 'product.form.quantity' | t }}</label>
<input type="number" id="quantity" name="quantity"
{% if product.tags contains "MIN4" and current_variant.inventory_management == 'shopify' -%}
value="4" min="4"
{% else %}}
value="1"
{% endif %}
{% if current_variant.inventory_management == 'shopify' and current_variant.inventory_policy == 'deny' -%}
max="{{ current_variant.inventory_quantity }}"
{% endif %} required>
</span>
Diana37
Visitor
1 0 0

Hello, good afternoon
this code is exactly what I need
but I don't know where to put it
can you help me please?

I don't know if I have to delete anything from the original code.

Dalila2
Tourist
28 0 2

Ou est ce qu'il faut mettre exactement le morceau de code dans le main-product.liquid?

epidote
Shopify Partner
5 1 1

Thanks for the code @KikyChen but for anyone finding this you also need to edit the main.cart file and any cart drawer liquid file with similar code otherwise they can just reduce the quantity there after adding product to cart. Also, warning "tags" don't appear to be a valid selector in the cart or cart drawer, maybe use slug or title as qualifier. 

AvadaCommerce
Shopify Partner
3879 839 973

Hi @bcomst 

 

You could consider using third-party apps such as Order Limits ‑ MinMaxify. They help you define minimum and maximum product and cart limits for your orders, from simple to complex.

 

I hope this helps you.

banned
Lashenvypro
Tourist
10 0 4

Hi, do you know if it is possible to exclude MOQ from certain customers? I am looking or something similar on our store. We sell salon supplies but also have our own salons, which they order their stock off our store at special wholesale prices through another app as a tagged customer.

 

For a particular product, we want general customers to purchase MOQ of 5, but for our salons, they have no minimum order requirements. Is this possible with this app?

Dirk
Shopify Staff
2396 257 529

Hey, @bcomst 

 

I'd also suggest taking a look at the app OrderLogic by Oiizes. With this app, you can set limits on how few or how many of each product your customers can order. If there is anything else I can help you with, please let me know.

 

If there is anything else I can help you with, please let me know.

Dirk | Social Care @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Lashenvypro
Tourist
10 0 4

Hi Dirk, do you know if it is possible to exclude MOQ from certain customers? I am looking or something similar on our store. We sell salon supplies but also have our own salons, which they order their stock off our store at special wholesale prices through another app as a tagged customer.

 

For a particular product, we want general customers to purchase MOQ of 5, but for our salons, they have no minimum order requirements. Is this possible with this app?

EFOLI-Emilia7
Shopify Partner
349 10 38

Hello, Have you got the solution? If not, then you can try the MultiVariants - Bulk order app.

 

You need to create a product in Shopify and under the main product create variants that will be visible on the product page. So, all the variants will display under the main product and there will be a quantity selector for each variant. Your customer can choose their own combination of all products. 

With this app, you can set the min and max quantity, so your customer must choose that quantity before going to the cart page. Additionally, through this app, you can apply restrictions for minimum-maximum quantities, predefined bundles, interval quantities, limits on variants, and orders that can be achieved. These restrictions can be set specifically on any particular product or a specific group of products also by using type, tag etc. Restrictions will be working also on non-variant products also.

 

You’ll get 3 days of trial along with great customer support for exploring all other features.

 

Here is the Sample product and here is the Sample store with more available features.

Restriction for Non-variantRestriction for Non-variant

 

banned