display product label on “out of stock ” products [closed]
-
13-12-2019 - |
Question
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.
Solution
Try this
<?php $stockItem = $_product->getStockItem(); ?>
<?php if (!$stockItem->getIsInStock()): ?>
<span class="out-of-stock"><span>Sold Out</span></span>
<?php endif; ?>
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange