Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello, I'm trying to add the below code I found to add MOQ but I'm not sure where to paste it in. My theme has quite a few instances of quantity. I'm certainly a noob to this so any help would be greatly appreciated!
<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>
With technical and code you must make an effort to be specific.
You must remember not everyone knows what your seeing, avoid ambiguity.
Not everyone has your theme or access to it, provide accessible urls, or code samples(do not paste giant walls of code).
In vague general terms quantity customizations require changing the product form.
For some themes start from the product template trace the sections and snippets to find the product form editing/replacing it's existing quantity behavior.
For other themes use the form attribute to link the new inputs to the main product form while disabling the old quantity.
If you just need this customization created then contact me by my email for services.
Contact info in forum signature.
ALWAYS please provide context, examples: store url, theme name, post url(s) , or any further detail in ALL correspondence.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Thank you Paul. Below is a link to my website where I'm hoping I can add an MOQ. Sorry for the lack of clarity in my initial post. The goal is to add an MOQ to this product (and all other products).
https://28cd87-a8.myshopify.com/products/style-01-ej5na-r3yz9
That's studio , based on the dawn theme
https://github.com/Shopify/dawn/blob/main/sections/main-product.liquid#L255
Ignore the quantity_rule stuff if you not using B2B features of a shopifyPlus plan.
You may need to remove novalidate from the main form in buy-buttons snippet
https://github.com/Shopify/dawn/blob/main/snippets/buy-buttons.liquid#L51
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Would this be a better script to use? I'm still not understanding where it needs to go:
<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 %}
My assumption is that the code I need to edit is within this area, but I'm not sure where to paste/replace it. I've tried a few areas but none are having the expected result
{%- when 'quantity_selector' -%}
<div
id="Quantity-Form-{{ section.id }}"
class="product-form__input product-form__quantity{% if settings.inputs_shadow_vertical_offset != 0 and settings.inputs_shadow_vertical_offset < 0 %} product-form__quantity-top{% endif %}"
{{ block.shopify_attributes }}
>
{% comment %} TODO: enable theme-check once `item_count_for_variant` is accepted as valid filter {% endcomment %}
{% # theme-check-disable %}
{%- assign cart_qty = cart
| item_count_for_variant: product.selected_or_first_available_variant.id
-%}
{% # theme-check-enable %}
<label class="quantity__label form__label" for="Quantity-{{ section.id }}">
{{ 'products.product.quantity.label' | t }}
<span class="quantity__rules-cart{% if cart_qty == 0 %} hidden{% endif %}">
{%- render 'loading-spinner' -%}
<span
>(
{{- 'products.product.quantity.in_cart_html' | t: quantity: cart_qty -}}
)</span
>
</span>
</label>
<div class="price-per-item__container">
<quantity-input class="quantity" data-url="{{ product.url }}" data-section="{{ section.id }}">
<button class="quantity__button" name="minus" type="button">
<span class="visually-hidden">
{{- 'products.product.quantity.decrease' | t: product: product.title | escape -}}
</span>
{% render 'icon-minus' %}
</button>
<input
class="quantity__input"
type="number"
name="quantity"
id="Quantity-{{ section.id }}"
data-cart-quantity="{{ cart_qty }}"
data-min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
{% if product.selected_or_first_available_variant.quantity_rule.max != null %}
data-max="{{ product.selected_or_first_available_variant.quantity_rule.max }}"
max="{{ product.selected_or_first_available_variant.quantity_rule.max }}"
{% endif %}
step="{{ product.selected_or_first_available_variant.quantity_rule.increment }}"
value="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
form="{{ product_form_id }}"
>
<button class="quantity__button" name="plus" type="button">
<span class="visually-hidden">
{{- 'products.product.quantity.increase' | t: product: product.title | escape -}}
</span>
{% render 'icon-plus' %}
</button>
</quantity-input>
You can go to your Online Store > Themes > Customize > Products, open product template you are using for your products, click Add block under Product information > choose Custom liquid, add code to Liquid code of block, drag and drop this block to place you want it display and Save template
- Solved it? Hit Like and Accept solution!
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025