cancel
Showing results for 
Search instead for 
Did you mean: 

How to add In stock / out of stock label for products in category page

How to add In stock / out of stock label for products in category page

I'm trying to add a in stock / out of stock label for all products on the category page. I've seen it on a lot of other webshops but haven't been able to figure out how.

Example of what I'm trying to achieve:
https://imgur.com/a/WMtvFO8

1 REPLY 1

Re: How to add In stock / out of stock label for products in category page

@xshadiumxg0889 

Find the list.phtml file which gets called in the category pages.

For example: app/design/frontend/rwd/default/template/catalog/product/list.phtml

 

Now, add the below code where you want to show label/status

<?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
    }
?>
Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.