[Minimal Theme] Set a minimum purchase quantity for a specific product via code

Ela_V_TSM
Explorer
56 2 7

Hello, all! Wanted to ask around if anyone has ever done this.

We wanted to have a minimum purchase quantity for a specific product in the store. I was hoping to just have this coded since my boss prefers to minimize costs for the store.

I've already edited the product page successfully by editing the code in product-template.liquid into this:

 

<div class="product-single__quantity{% unless section.settings.product_quantity_enable %} is-hidden{% endunless %}">
  <label for="Quantity">{{ 'products.product.quantity' | t }}</label>
  <input type="number" id="Quantity" name="quantity"
    {% for tag in product.tags %}
      {% if tag contains 'min5' %}
        value="5" min="5"
      {% else %}
        value="1" min="1"
      {% endif %}
    {% endfor %} class="quantity-selector">
</div>

 

 

Now, the current problem I only have is that the customer can still reduce the number of items they can purchase on the cart page. I've tested the codes below but they don't seem to work:

 

<div class="grid__item one-third text-center">
  <label for="updates_{{ item.key }}" class="cart__mini-labels">{{ 'cart.label.quantity' | t }}</label>
  <input type="number" data-key="{{ item.key }}" class="cart__quantity-selector" name="updates[]" id="updates_{{ 
    item.key }}" value="{{ item.quantity }}"
    {% for tag in item.tags %}
      {% if tag contains 'min5' %}
        min="5"
      {% else %}
        min="0"
      {% endif %}
    {% endfor %}
    aria-label="{{ 'cart.label.quantity' | t }}">
</div>

 

 Would appreciate if anyone can add in more info. Thanks!

Email: ela.v.tsm@gmail.com
Reply 1 (1)
JoesIdeas
Shopify Expert
1429 127 385

I would use JavaScript and attach an event listener to the add to cart button / checkout button.

Then, if they click the add to cart button but haven't met the minimum, rather than submitting the add to cart, you could make it show a message that says "You must purchase....".

And on the cart page, same thing, you could have a message show if they haven't met the minimum, and prevent them from checking out until they've satisfied that.

Creator of Order Automator (auto tag orders / customers + auto fulfillment + more automations). Creator of Shopify Analyzer (1st performance analysis tool for Shopify sites, free for the community). Founder of Speed Boostr (Shopify optimization experts + app developers). More apps: Theme Scientist (A/B testing), Tip Jar (add a tip button), File Optimizer (optimize CSS, JS, Liquid).