I want to display a product label "out of stock" in frontend for those products which are set out of stock in the admin panel.

Let me know if you need any clarifications.

Please help me to find a solution.


2 Answers 2


Try this

<?php $stockItem = $_product->getStockItem(); ?>
<?php if (!$stockItem->getIsInStock()): ?>
    <span class="out-of-stock"><span>Sold Out</span></span>
<?php endif; ?>
  • i placed that code in list.phtml and view.phtml , but it's not working, please guide me? May 26, 2015 at 9:22
  • wer you had pasted can you show May 26, 2015 at 9:30
  • you have to place the code in the foreach loop inside this loop foreach ($_productCollection as $_product): ?> May 26, 2015 at 9:31
  • please check here : pastebin.com/engLxxWc this is list.phtml , but still not displaying May 26, 2015 at 9:34
  • may be because your listing product is in the grid mode and you added the code in the list mode.please try to put above code in the grid mode.you can see below in the same file May 26, 2015 at 9:36

To display the "out of stock" label on product view page, write the below code in the file app/design/frontend/rwd/default/template/catalog/product/view.phtml

$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
$qty = $stock->getQty();
if($qty <= 0)
<span class="out-of-stock"><span>Sold Out</span></span>

And if you want the label on the category page, write in app/design/frontend/rwd/default/template/catalog/product/list.phtml

NOTE : It is assumed that you are using magento-1.9 or greater

  • yes, i am using 1.9.0 , i wrote above code in both list and view.phtml files in custom theme. May 26, 2015 at 9:28
  • still not achieved?? May 26, 2015 at 9:29
  • i've edited my answer May 26, 2015 at 9:33
  • can you please tell me where i have to place your code here : pastebin.com/engLxxWc May 26, 2015 at 9:36
  • after this line <?php foreach ($_productCollection as $_product): ?> NOTE: this line occurs twice May 26, 2015 at 9:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.