How to get product stock qty and stock information by product id in Magento 2?

You can get Product stock related information using the Catalog Inventory module of Magento 2.

Magento\CatalogInventory\Api\StockRegistryInterface is used for getting Stock Information from the Product.

If you want to only get Product Quantity and Product status might be it’s in stock or not then refer Get Product quantity from product object

Let’ create Block file and call function from a block,

Now, We can get the product stock information by id and SKU in a template file using the below way.

The output will be something like below,

You can get qty, min_sale_qty, is_in_stock, backorder, stock_id, website_id related data with ease.