Show the remaining inventory of a variant on product pages
You can add a message on the product page or featured product section that displays the number of items you have in stock when inventory runs low on a product variant. For this message to display, you need to activate inventory tracking for the product.
The steps for this customization vary depending on your theme. Click the button for your theme and follow the instructions.
Steps for Debut
Edit theme.liquid
From your Shopify admin, go to Online Store > Themes.
Find the theme you want to edit, and then click the ... button > Edit code.
From the Layout directory, open theme.liquid.
Find the closing </head> tag in the code. On a new line above the closing </head> tag, paste the following code:
Click Save.
Edit product-template.liquid or featured-product.liquid
From the Sections directory, open product-template.liquid or featured-product.liquid:
Open product-template.liquid to add this feature to product pages.
Open featured-product.liquid to add this feature to the featured product section on the home page.
Find{% form 'product'. Above this tag, add the following code:
The code above outputs Stock: x. You can change the wording by adjusting the content in the <p> tags. Make sure to include {{ current_variant.inventory_quantity }} in your <p> tags.
At the bottom of the file, add the following code:
Click Save.
Edit theme.js.liquid or theme.js
The changes that you need to make to these files depend on the version of Debut that you're using.
Versions 17.8.0 and below
Open theme.js.liquid or theme.js.
Findtheme.Product = (function(). Below this.selectors = {, add the following code:
In the same file, find_updateAddToCart: function(evt) {. Directly below, add the following code:
Findif (variant.available) {. Before the } else { statement, add the following code:
The code above outputs Stock: x. You can change the wording by adjusting the content in the <p> tags. Make sure to include ${variantStock[variant.id]} in your <p> tags.
Click Save.
Versions 17.9.0 and above
Open theme.js.liquid or theme.js.
Findtheme.Product = (function(). Below this.selectors = {, add the following code:
In the same file, find_setProductState: function(evt) {. Directly below, add the following code:
In the same function, findif (!variant) {. After the closing } bracket, add the following code:
The code above outputs Stock: x. You can change the wording by adjusting the content in the <p> tags. Make sure to include ${variantStock[variant.id]} in your <p> tags.
Click Save.
Can’t find the answers you’re looking for? We’re here to help.