Maximum Order Quantity

I’m looking for help in limiting individual orders from including more than 3 items. Is there a way to either limit the max quantity of a given product or create a max total items in an order?

Hey Jesse, welcome to the community =]

This should cover the Add Product Page:

<script>
  (function(){
    var qinput = document.getElementById("quantity");
      
    qinput.setAttribute("type","number");
    qinput.setAttribute("max",3);
  })();
</script>

I’ll update with the cart end of things.

Here is the final code I came up with, which should set limits on any orders with a single product type.

Just stick it in your Shopping Cart Theme’s “Custom Footer”:

<script>
(function(){
	// set limit for input field
	var limit = 3;

	// get product page quantity
	var qinput = document.getElementById("quantity");
	// get checkout qty
	var cartqinput = document.getElementsByName("qty_1");

	setLimitOnAttr(qinput);
	setLimitOnAttr(cartqinput[0]);

	function setLimitOnAttr(attr) {
		// if it's not set, exit
		if (!attr) { return; }

		// set to number type field
		attr.setAttribute("type","number");
		// set max value to limit
		attr.setAttribute("max", limit);
	}
})();
</script>

Let me know if you have any questions!

1 Like

It works! Thanks MEarl!

1 Like