I have searched a lot and since I am new to magento I would like your help. I want to display my stock quantity on my product details page. Can someone please give me a step by step configuration including files to modify?
Admin panel -> Go to -> store -> configuration-> Catalog -> Inventory -> Display Products Availability in Stock on Storefront ->
Select Yes from the dropdown -> Click on save config button !
Clear the cache and check at frontend - it will not display !
for total quantity $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface'); echo $StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId()); and if you want to get status $stockItem = $objectManager->get('\Magento\CatalogInventory\Model\Stock\StockItemRepository'); $productId =1; // YOUR PRODUCT ID $productStock = $stockItem->get($productId); $data_p = $productStock->getData(); echo $data_p['is_in_stock']; //1 in stock 0 for out of stock