Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anilmeena/cafd15e7946b1151428b9051a73e43c9 to your computer and use it in GitHub Desktop.
Save anilmeena/cafd15e7946b1151428b9051a73e43c9 to your computer and use it in GitHub Desktop.
Shopify Display Product Inventory of Variants
// In product.liquid, locate this code:
// {{ product.description }}
// Below that, add this:
<p id="inventory">{% assign variant = product.variants.first %}
{% if variant.available %}
{% if variant.inventory_management != '' %}
{{ variant.inventory_quantity }} in stock
{% else %}
In stock
{% endif %}
{% endif %}</p>
// Then locate this line of JavaScript code in the same template:
// jQuery('#price-field').html(Shopify.formatMoney(variant.price, "{{shop.money_with_currency_format}}")); // update price field
// Right below, add this code:
if (variant.inventory_management !== '') {
jQuery('#inventory').text(variant.inventory_quantity + ' in stock');
}
else {
jQuery('#inventory').text('In stock');
}
// Then locate this:
// jQuery('#price-field').text(message); // update price-field message
// On the next line, add this:
jQuery('#inventory').html('&nbsp;');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment