Magento 2 Show Stock Quantity on Product Page

By default, Magento only shows stock status. In this tutorial, we will show you how to show stock quantity on product page on Magento 2.

You can get the final package for this feature at the end of this post. 

List of files we will create:

  • app/code/Metagento/StockQty/view/frontend/layout/catalog_product_view.xml
  • app/code/Metagento/StockQty/Block/Catalog/Product/View.php
  • app/code/Metagento/StockQty/view/frontend/templates/catalog/product/view.phtml
  • app/code/Metagento/StockQty/etc/frontend/routes.xml
  • app/code/Metagento/StockQty/Controller/Index/Index.php

Layout file



Block file



Template file



Route file






After creating above files, clear magento cache to see the change.


  • Simple product page

Show Stock Quantity on Simple Product Page

  • Configurable product page

Show Stock Quantity on Configurable Product Page

That’s how to show stock quantity on product page, hope this small feature will be helpful.

You can get this module on Github:

If you have any question or need any assistance, leave us a message.