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

app/code/Metagento/StockQty/view/frontend/layout/catalog_product_view.xml

 

Block file

app/code/Metagento/StockQty/Block/Catalog/Product/View.php

 

Template file

app/code/Metagento/StockQty/view/frontend/templates/catalog/product/view.phtml

 

Route file

app/code/Metagento/StockQty/etc/frontend/routes.xml

 

Controller 

app/code/Metagento/StockQty/Controller/Index/Index.php

 

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

Result

  • 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: https://github.com/metagento/magento-2-stock-qty

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

Magento 2 Show Stock Quantity on Product Page
5 (100%) 4 votes

Written By Metagento

Leave a Reply

Your email address will not be published.