Showing results for 
Search instead for 
Did you mean: 

Display Out of Stock Label


Display Out of Stock Label



I have been trying to figure out how can I display the out of stock label instead of Add to Cart when the QTY of the product is 0.


I have enabled the allow back orders, since from the shop, I need to be able to sell as back orders, but online I don't wont that option.


But when I enabled the backorder option, magento stop putting products as out of stock.


Does any one know how can I check if the QTY is 0 and in that case display the Out of Stock label?


Re: Display Out of Stock Label

Hi @robertbits


i understand your problem and certainly yes you can do it that !


Here is the solution link of your problem refer this -


Override in the theme or in your custom module and add the give code over there same like mention in the link and then check it will works !


Hope it helps

if issue solved,Click Kudos & Accept as Solution

Re: Display Out of Stock Label

Hi @ManthanDave,


I have tried to do as the link said, but I ma stuck with this error and could not figure out if 'Mage' is a function in magento itself or a third party extensions since I am getting this error:

Fatal error: Uncaught Error: Class 'Mage' not found in E:\xampp\htdocs\magento\app\design\frontend\Magento\Magento_Catalog\templates\product\list.phtml:99 Stack trace: #0 E:\xampp\htdocs\magento\vendor\magento\framework\View\TemplateEngine\Php.php(59): include() #1 E:\xampp\htdocs\magento\vendor\magento\framework\View\Element\Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\ListProduct\Interceptor), 'E:/xampp/htdocs...', Array) #2 E:\xampp\htdocs\magento\generated\code\Magento\Catalog\Block\Product\ListProduct\Interceptor.php(557): Magento\Framework\View\Element\Template->fetchView('E:/xampp/htdocs...') #3 E:\xampp\htdocs\magento\vendor\magento\framework\View\Element\Template.php(300): Magento\Catalog\Block\Product\ListProduct\Interceptor->fetchView('E:/xampp/htdocs...') #4 E:\xampp\htdocs\magento\vendor\magento\framework\View\Element\AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml() #5 E:\ in E:\xampp\htdocs\magento\app\design\frontend\Magento\Magento_Catalog\templates\product\list.phtml on line 99


Re: Display Out of Stock Label

Hi @ManthanDave,

I didn't manage to work with the link you suggested since I was getting an error on 'Mage'.


but in the mean time I manage to work something using this code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
echo $StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());

now my next problem, is that when I set this to hide the add to cart, I could not find a way to display the Notify me when this product is in stock link.


Do you know how can I add this module to the view.html of the catalog?