Magento – Magento 2 : How to Display Product Id on Product View Page

frontendmagento2product

I want to display product id on product view page when user click on product.

For ex :- This product id is 1. When This page is display on this page I want to display product id 1.

How can I get ?

Please help me…..

enter image description here

Best Answer

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();

$registry = $objectManager->get('\Magento\Framework\Registry');

$currentProduct = $registry->registry('current_product');

echo $currentProduct->getId();

You can get current product id using this code.

Related Topic