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?


From the

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 !

Magento 2: Display/Disable Out of Stock Product – Magento 2.3

Stock Options

  • getting or not ?? – Rk Rathod Sep 5 '19 at 9:58
  • If i do as you instructed i cannot display the product quantity on product page just "In stock". I need my clients to be able to see actual product quantity instead of "In stock". Meaning "In stock (qty)". – Gogoulos Tasos Sep 5 '19 at 10:18
  • use custom theme ? – Rk Rathod Sep 5 '19 at 10:20
  • Yes i use custom Theme SM Autostore from Magentech. – Gogoulos Tasos Sep 5 '19 at 10:21
  • wait let me update answer – Rk Rathod Sep 5 '19 at 10:24
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

  • Can you please instruct me in which file i must edit? Also another thing is not to display negatives. I mean that if stock status in -1 to display 0. – Gogoulos Tasos Sep 3 '19 at 13:25
  • vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml or depend on your cutome theme ==> app/design/frontend/Lucenttheme/Inno/Magento_Catalog/templates/product/view/addtocart.phtml or any in view folder depend on your design and your place. thanks – sarvesh Dineshkumar Patel Sep 3 '19 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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