Skip to content
Product Order Limits (Minimum and Maximum) - Free Tutorial
Browse other ways to boost conversion rate & profit

Product Order Limits (Minimum and Maximum) - Free Tutorial

In this customization, we are adding product order limits, so you can set the maximums and minimums that customers can buy.

You might not want your customers to over-order a promotion so you can set a maximum. Or if you need to save on shipping costs you can set a minimum so they purchase in multiples.

Normally this is a feature that you have to pay for by installing an app, but in this video I’m going to show how to add it to your store for free.

Compatible Themes: This code should work on all free Shopify themes (Dawn, Refresh, Craft, Studio, Publisher, Crave, Origin, Taste, Colorblock, Sense, Ride, Spotlight).

 

Create metaobject and metafields

  • Create quantity_rule metaobject with fields name, increment, min, and max
    • required
    • integer, min value 1
  • Create Product metafield quantity_rule with metaobject type quantity_rule
  • Create Variant metafield quantity_rule with metaobject type quantity_rule
  • Create metaobject entries

Edit Theme Code

Edit settings_schema.json

  {
    "name": "Custom Quantity Rules",
    "settings": [
      {
        "type": "checkbox",
        "id": "use_quantity_rules",
        "label": "Enable custom quantity rules",
        "default": false
      },
      {
        "type": "checkbox",
        "id": "use_total_product_quantity",
        "label": "Use total product quantity",
        "info": "Add the total of all variant quantities together",
        "default": false
      }
    ]
  }

Edit main-cart-items.liquid and cart-drawer.liquid

  • Replace item.variant.quantity_rule with quantity_rule
  • Add the following code:
    {%- if settings.use_quantity_rules -%}
      {%- if settings.use_total_product_quantity -%}
        {% assign quantity_rule = item.product.metafields.custom.quantity_rule.value %}
        {% assign total_product_quantity = 0 %}
        {% assign global_max = item.product.metafields.custom.quantity_rule.value.max | plus: 0 %}
        {% for cart_item in cart.items %}
          {% if cart_item.product.id == item.product.id %}
            {% assign total_product_quantity = total_product_quantity | plus: cart_item.quantity %}
          {% endif %}
        {% endfor %}
        {% assign item_remaining_qty = global_max | minus: total_product_quantity %}
        {% assign max_for_variant = item.quantity | plus: item_remaining_qty %}
        {% if max_for_variant > global_max %}
          {% assign max_for_variant = global_max %}
        {% endif %}
       {% else %}
         {% assign quantity_rule = item.product.selected_or_first_available_variant.metafields.custom.quantity_rule.value %}
      {% endif %}
    {% else %}
      {% assign quantity_rule = item.variant.quantity_rule %}
    {% endif %}
    
  • Replace the input max max="{{ quantity_rule.max }}" with:
    {% if settings.use_total_product_quantity %}
      max="{{ max_for_variant }}"
    {% else %}
      max="{{ quantity_rule.max }}"
    {% endif %}
    

Edit main-product.liquid

  • Replace product.selected_or_first_available_variant.quantity_rule with quantity_rule
  • Add the following code:
    {% if settings.use_quantity_rules %}
     {% if settings.use_total_product_quantity %}
       {% assign quantity_rule = product.metafields.custom.quantity_rule.value %}
     {% else %}
       {% assign quantity_rule = product.selected_or_first_available_variant.metafields.custom.quantity_rule.value %}
     {% endif %}
    {% else %}
    {% assign quantity_rule = product.selected_or_first_available_variant.quantity_rule %}
    {% endif %}
    
    {% if settings.use_quantity_rules and settings.use_total_product_quantity %}
    {% assign cart_qty = 0 %}
    {% for item in cart.items %}
      {% if item.product.id == product.id %}
        {% assign cart_qty = cart_qty | plus: item.quantity %}
      {% endif %}
    {% endfor %}
    {% else %}
    
    ... existing cart_qty assignment...
      
    {% endif %}
    
    
Browse other ways to boost conversion rate & profit

Here's 5 Ways We Can Help You

Here's 5 ways we can help you:

  1. Access to our downloadable AI agent workflows, $4.3 million theme, $100k/mo Low-Risk Facebook Ads SOP, support from us personally, and more for $9: Click here
  2. Get our high-converting theme that generated us $4.3M in sales: Click here
  3. Find Conversion Leaks that cost you orders and profit: Click here
  4. Work with us to add $10,000 to your store in 10 weeks. Send an email to hello [at] theprompted.co with the subject line “10k”
  5. Email us to work privately on custom development. Send an email to hello [at] theprompted.co and use the subject line "custom", and then detail out what you have in mind, including all specifics.