Select Page

How to Show Product Stock Remaining Items in Magento 2

Divya Prakash
Published: June 21, 2022

In this article, You will learn how to get the products Qty left in stock. We also show you the way to even customize them by adding a custom message for stock low Qty.

Please follow these steps one by one:

Step-1: On the Admin Panel, go to the Stores menu then under the Settings section you find Configuration options ( Stores > Settings > Configuration ) See the Image below


Step-2: On the left panel, go to the Catalog tab and then select the Inventory option ( Catalog > Inventory )
Step-3: Enter the number like 5 in the Display X left Threshold field. In the Store View, Buyers can see “Only 5 left” or the lowest quantity.


You can customize the message “Only 5 left” by overriding this template file.
Follow the path: \vendor\magento\module-catalog-inventory\view\frontend\templates\stockqty\default.phtml

Searching for an experienced
Magento 2 Company ?
Read More

Rewrite the code below:

<?php if ($block->isMsgVisible()): ?>
<div class="availability only" title="<?= /* @escapeNotVerified */ __('Only %1 item(s) left in stock', ($block->getStockQtyLeft())) ?>">
<?= /* @escapeNotVerified */ __('Only %1 item(s) left in stock', "<strong>{$block->getStockQtyLeft()}</strong>") ?>
<?php endif ?>

By Following the steps, the message “Only 5 items left in stock” we get. However, by Magento 2 default, we can use the above option for simple products since we maintain the inventory for simple products.

You can also check the below link Magento docs which give you more information about inventory stocks and also check our other blogs.


You can also check our other blogs