Custom Quantity per Product?

New Member
1 0 0


Can anyone suggest how I can set a "default quantity" on a product level?  I sell Autoparts, some applications take 2 pcs, some take 1 pc...  When a customer does a search and a product that typically would be sold as 2 shows up, I would like to prefil the quantity as "2" however the customer would be able to change this when adding to the cart. 

1151 0 118

In your product template (or more likely a snippet included into the product template) you probably have something like:

<input type="number" class="quantity" name="quantity" id="quantity" value="1" />

You need to have some means of putting the default quantity into that value field. Two thoughts come to mind: a tag that you would need to search for and parse or a metafield.

Say you tagged products needing something other as Qty 1 like this

DefaultQuantity:X where X is the default quantity for that product. For example, DefaultQuantity:2 would result in "2" being in that value field above.

{% assign myDefault = "1" %}
{% for tag in product.tags %}
  {% if tag contains 'DefaultQuantity:' %}
    {% assign myDefault = tag | remove: 'DefaultQuantity:' %}
    {% break %}
  {% endif %}
{% endfor %}

<input type="number" class="quantity" name="quantity" id="quantity" value="{{ myDefault }}" />

If you are familiar with metafields (you need a metafield editor app or a browser extension from Freak Design), you could do it that way. For example, for those products that are exceptions to the norm (the majority of your products, you could set a metafield and then reference it in the input tag. Suppose you stored it in the namespace "mydata" with a key of "default_quantity".

<input type="number" class="quantity" name="quantity" id="quantity" value="{% if product.metafields.mydata.default_quantity %}{{ product.metafields.mydata.default_quantity }}{% else %}1{% endif %}" />

translation: if the metafield for default quantity exists, use that value, else use 1 (or whatever number you use for the most common default. ::: Solid Wood TV Furniture for Enthusiasts. Made in USA.
1 Like