I tried using isSaleable(), getSaleableItem(), is_in_stock, without success.

I'm new to Magento and I don't have much knowledge.


1 Answer 1


Try this in final_price.phtml file

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productStockObj = $objectManager->get('Magento\CatalogInventory\Api\StockRegistryInterface')->getStockItem($productId);

and you can add condition like this

if ($productStockObj->getIsInStock())

Reference Link

  • It didn't work, it returns the value empty Commented Sep 21, 2023 at 12:25
  • <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productStockObj = $objectManager->get('Magento\CatalogInventory\Api\StockRegistryInterface')->getStockItem($productId); ?> <?php if ($productStockObj->getIsInStock()) : ?> OK <?php else : ?> NOK <?php endif; ?> Commented Sep 21, 2023 at 12:27
  • I tested in magento2.4.6 and it's working for me. are you using a custom theme or module? Commented Sep 21, 2023 at 12:50
  • 1
    app/design/frontend/{Theme}/{name}/Magento_Catalog/templates/product/price/final_price.phtml in this location can you please add code that I added the link in the answer and check if it's working or not? Commented Sep 21, 2023 at 13:07
  • 1
    print the data and check print_r($productStockObj) Commented Sep 21, 2023 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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