How can I code a minimum order quantity metafield for specific products?

Hey all,

I wonder if you are able to assist with some coding for creating minimum order for select products.

I have created a metafield that displays text below the quantity box

https://prnt.sc/5MvZsogeF8iZ

I have also created a second metafield which is the same but just a number

https://prnt.sc/TuxeJgmDCgAq

I understand that I need to alter the code so that it will only allow a customer to order that minimum amount but that is where I am now a little stuck I know I need to alter this code

<div class="{{ block_width }}clearfix">
  <span class="quantity form">
    <button type="button" class="btn qtybtn icon-minus ignore qtyminus_{{ section.id }} text-center {{ template }}-template" field="updates_{{ section.id }}" aria-label="{{ 'products.general.minus' | t | escape }}">{%- render 'icons.theme', icon: 'minus', size: 28 -%}</button>
    <label for="updates_{{ section.id }}" class="visually-hidden">{{ 'products.general.quantity' | t }}</label>
    <input name="quantity" type="number" inputmode="numeric" pattern="[0-9]*" value="{% unless variant.available %}0{% else %}1{% endunless %}" min="{% unless product.available %}0{% else %}1{% endunless %}" class="ignore quantity item-qty text-center" field="error_{{ section.id }}" id="updates_{{ section.id }}"{% if variant.inventory_management and variant.inventory_policy != 'continue' %} max="{{ variant.inventory_quantity }}"{% endif %} />                   
    <button type="button" class="btn qtybtn icon-plus ignore qtyplus_{{ section.id }} text-center {{ template }}-template" field="updates_{{ section.id }}" aria-label="{{ 'products.general.plus' | t | escape }}">{%- render 'icons.theme', icon: 'plus', size: 28 -%}</button>       
    <label class="stock error hidden" id="error_{{ section.id }}">.</label>
  </span>
</div>

and that somewhere I need to add

(( product.metafields.custom.minimum_order_no ))

But the tutorials I have seen show a much simpler code. Could anyone direct me as to where I need to add this for it to process correctly.

Additionally do I also have to do anything with the cart page?

Just giving this a bump to see if there is anyone out there who can help.

I would reference this video, it helped me and you can figure out how to make it work on multiple themes.

https://www.youtube.com/watch?v=X_5xAl1oaAc

Is it possible to make this applicable to variants within a product line? In other words, can I make this size (.25" x 3" x 3") start at 15, the next size start at quantity of 10, etc?

Actually I have a better suggestion for you. You can force your customers to purchase a minimum quantity for some specific products using the Cart Lock https://apps.shopify.com/cart-lock app very easily. Here is how you can do it:

  1. Open the app and click on the “Add a new rule” button.
  2. Click “Add a new condition” and select the “Single item quantity” then add 2 in the “Block if less than” field.
  3. Click “Add a new condition” again and select the “Products” then add your desired items.
  4. In the “Error message” field, add an appropriate message which will be displayed in the checkout page.
  5. Save the rule.

It will work at the checkout page level as well so it is a very solid solution. Thanks.