Check out my Youtube channel

Wholesale Minimum Quantity or Box Quantity in Shopify - No App

If you have a wholesale store then you might want to sell in bulk quantities, and not allow people to buy just 1 item.

I’m going to be showing you two things:

  1. How to set a minimum order quantity, so customers can buy any amount higher than that quantity. So if the minimum is 6 they can buy 7 or 8 etc..
  2. How to set a “box quantity” so people can only buy multiples of that number i.e. you sell a box of 6, so people should only buy multiples of 6 - like 6,12,18,24 etc…

Let’s get started.

Define the metafield

We’re going to be using metafields so that you can set the MOQ or box quantity per-product.

Go to Settings > Metafields and define the metafield. Call it something like minimum quantity or box quantity, whichever makes more sense for your needs.

Now get a product your’e going to be testing on and fill out the metafield.

Editing your quantity field.

On Dawn (also Sense, Craft, Crave) theme it’s going to be inside a file called ‘main-product.liquid’

First we want to get the value from the metafield:

{% assign min_quantity = product.metafields.wholesale.min_quantity %}

We are going to be replacing the fields initial value with {{ min_quantity }} so make sure you set a fallback in case the product does not have this value filled.

{% if min_quantity == blank %}
  {% assign min_quantity = 1 %}
{% endif %}

Now you can edit your quantity field code

  • modify the min attribute
  • modify the value attribute

min="{{ min_quantity }}"

value="{{ min_quantity }}"

You also might want to prevent people from manually editing this, although this is a weird thing for them to do. But I think its fine to disable it and force people to click the + and - buttons, unless they need to add like 1000. In that case I wouldnt do it.

onkeydown="return false"

And if you’re doing box quantity, you will want to add a ‘step’ attribute:

step="{{ box_quantity }}"

Altogether, my code looks like this:

{% assign box_quantity = product.metafields.wholesale.box_quantity %}
{% if box_quantity == blank %}
  {% assign box_quantity = 1 %}
{% endif %}

<input class="quantity__input" 
  type="number" 
  name="quantity" 
  id="Quantity-{{ section.id }}" 
  min="{{ box_quantity }}" 
  value="{{ box_quantity }}" 
  step="{{ box_quantity }}" 
  onkeydown="return false" 
  form="{{ product_form_id }}" 
  \>

Edit on the cart page

There is a quantity selector on the cart page and we want that to work the same way and not break our rules.

There are only a couple differences:

  • We need to put the word ‘item’ in front when we access the metafields. Since this is the cart template - we access the cart item, and inside of that is the product. So {{ item.product.metafields.wholesale.box_quantity }}
  • The value attribute should remain as {{ item.quantity }} - this is the amount that was added to cart.

Altogether my code on the cart page looks like this:

{% assign box_quantity = item.product.metafields.wholesale.box_quantity %}
{% if box_quantity == blank %}
  {% assign box_quantity = 1 %}
{% endif %}

<input class="quantity__input"
  type="number"
  name="updates\[\]"
  value="{{ item.quantity }}"
  min="{{ box_quantity }}"
  step="{{ box_quantity }}"
  onkeydown="return false"
  aria-label="{{ 'products.product.quantity.input_label' | t: product: item.product.title | escape }}"
  id="Quantity-{{ item.index | plus: 1 }}"
  data-index="{{ item.index | plus: 1 }}"
  \>

Bulk Edit the metafields

Ok so now all you need to do is enter the MOQ or box quantity for all your products.

This will be really slow one by one, so you need to use the bulk editor.

There is a trick to opening metafields in the bulk editor, and I explain it in this video:


Want posts like this in your inbox? Subscribe to the newsletter.

Comments

14 comments
  • Christine

    Hello, I really liked watching you video. But I can't seem to make it work for me. I am using the Trade Theme, and it has variations. The coding is different, a little more complex. I haven't been able to make it work. Do you have any suggestions?


  • Terry

    I have just updated my dawn theme and can no longer get this to work on the cart. Would you know what changes need to be made to get this to work on the cart again?


  • Harjot

    Hello,

    Any help with warehouse theme. I couldn't locate any code as per tutorial


  • hao

    I solved it successfully. Obviously your version is different from the current version, but I tried a few modifications and succeeded step by step. It does come up with +1 every time. But I successfully modified it from 6 to Multiply


    1 reply
    • leah

      Hi Hao, I also realised Eduard's version is different from the current Shopify version and I was unable to set the minimum order quantity. Do you mind sharing what modifications you made?


  • Shan Kazmi

    Thank you for this wonderful tutorial. I am having one issue though and I will really appreciate if you can let me know how to fix it. The issue I am encountering is that my step value is not working, I wanted to make it a box quantity and I am using box_quantity variable in step field but the quantity selector on my product and cart pages is taking step="1" only. How can I fix this?


  • Ahmed

    Thanks for a smooth step-by-step tutorial. I tried all of your code.. but it didn't worked for me, as it keeps on showing min quantity as "1".
    I'm using Dawn v10, and I see extra code lines in main-product.liquid...

    data-cart-quantity="{{ cart_qty }}"
    data-min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"

    Don't know what to do with above line? I tried removing them, but still its showing 1 although refreshed page multiple times and set metafields variable as 2 inside product details! Need help??


  • Benny

    Thanks for the Tutorial it's awesome!!!
    I've tried the code.... box qty. But it still keeps adding the 1.
    Lets say we have a box qty of 100... it works fine, but it is always adding 1 more. So the result is 101!

    what is going wrong in this case?


  • swork

    hi, thanks for tutorial but i cant change min quantity its always stuck at 1 it is actually changing in codes but not working

    (my theme spotlight)


  • Dor

    Hi, great video!! i was windering how can i make the same thing with the use of VARIANT metafield and not PRODUCT


  • Kim K

    Hi Ed and thanks for putting this out there! I'm trying to follow the tutorial, but find no code containing the word 'quantity' inside main-product.liquid (please see screencast here: https://drive.google.com/fi....

    Am I missing something very basic?


  • Amit Loomba

    HI, your reference is quite interesting.

    my requirement is i want some products in my shop to not to be sold in multiples in a single order. i mean there are some products that i want to sell not more than 1 in a single order. so i want to put a maximum limit of 1 for some products.

    can you tell me how to do that?


  • Jeff H

    Love the content as always Ed, relevant and to the point - thank you.
    Could an equivalent functionality for setting a maximum quantity be implemented with a similar approach to above?
    My theme is Drop (developer is We Are Underground). Cheers!


  • Bulkify

    Thank you, so much for sharing the informative content.

    If you own a Shopify store and are having trouble managing your data, try Bulkify today. Bulkify is a Shopify bulk edit app that allows you to bulk edit products with metafields and collections without using a CSV or Excel file. You can also use it to track the history of changes in your data.


  • Tomasz Lewandowski

    Amaizng content!

    I have done everything as in the video guide, however I can still go below the min value, any idea what's wrong?

    To start with I did not have the "min value" in my main-product.liquid

    My Code (prestige theme):

    {% assign min_quantity = product.metafields.wholesale.minimum_quantity %}

    {% if min_quantity == blank %}

    {% assign min_quantity = 1 %}

    {% endif %}

    <input type="text" class="QuantitySelector__CurrentQuantity" pattern="[0-9]*" name="quantity" value="{{ min_quantity }}" min="{{ min_quantity }}" onkeydown="return false" aria-label="{{ 'product.form.quantity' | t }}">

    P.S same applies to cart.


    1 reply
    • Eduard Fastovski

      Your issue is the type of input used in Prestige theme - input type="text".

      Usually inputs used for a number would be using input type="number" - https://developer.mozilla.o...

      But because yours is just a text input, it does not respond to 'min' or 'step'.

      I'm not sure why the theme developers did this. It might be laziness or there might be a specific reason (like they did not want the default arrows to display as you can see in the above link when hovering over the number field).

      Anyway, you can try changing the input type to "number". Hopefully that doesn't break anything. If it does break something, then I'm afraid you will need to look for a javascript solution instead.


      1 reply
      • Tomasz Lewandowski

        Thank you for such fast reply!

        I have changed the type="text" to type="number" and yes, on hover I can now see a small bracket (default arrows) that work as intended but by pressing "-" I can go below the set value.

        So wierd.

        I guess there is no way around it... you mentioned javascript solution, any chance you can elaborate?

        Regardless, thanks for your time!

        link