Skip to content

Instantly share code, notes, and snippets.

@zakhardage
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save zakhardage/c499672174e573efa240 to your computer and use it in GitHub Desktop.

Select an option

Save zakhardage/c499672174e573efa240 to your computer and use it in GitHub Desktop.
Inventory for Wholesale [Shopify]
{% for variant in product.variants %}
{% assign qty = qty | plus:variant.inventory_quantity %}
{% endfor %}
{% if qty > 0 %}
<label>Quantity ({{ qty}} available):</label>
<input type="text" name="quantity" id="quantity" value="1" onclick="this.select()" onkeyup="qtyCheck(this.value)" />
<button type="submit">add to cart</button>
{% else %}
<p>Sorry, this is temporarily unavailable.</p>
{% endif %}
<script>
function qtyCheck(qty) {
if(qty > {{ qty }}) {
alert("Sorry, we only have {{ qty available }}.");
document.getElementById('quantity').value = "{{ qty }}";
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment