Magento 1.9 – How to Display Stock Information on Product Page

custom-optionsmagento-1.9stockstock-status

I would like to display the stock status (In Stock | Sold Out) on the product page.

How can I achieve that?

Best Answer

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

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

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

Related Topic