Created
April 12, 2017 10:47
-
-
Save anilmeena/cafd15e7946b1151428b9051a73e43c9 to your computer and use it in GitHub Desktop.
Shopify Display Product Inventory of Variants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(' '); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment