How can I allow buying only more than X items of a Product?

Sometimes you want to restrict sales to a minimum quantity of products per order. You need to check quantity of item per products.

{% assign qty_valid = true %}
{% for product in order.products %}
  {% if product.qty < 5 %}
    {% assign qty_valid = false %}
  {% endif %}
{% endfor %}

Now, the variable returns true or false if all products in the cart have 5 or more items.

You can then use this varriable to perform logic operations, like hiding a button via CSS.

{% unless qty_valid %}
<style type="text/css">
{% endunless %}


1. What about restricting orders bellow a certain price amount?

You can perform a check on the {{ }} or any of the other variables: