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.....
$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.
You can use below code on template file from here . Please use your theme and if you dont have files here copy from vendor.
app/design/frontend/package/theme/Magento_Catalog/templates/product/view/
Packag and theme should be change as per your theme Add below code to get product id
<?php echo $_product->getId(); ?>
$_product->getId()
on phtml where you want product id. ofcourse related to product detail page.