How to get product ID in Magento_Catalog/template/view/my_custom_template.phtml file?

Trying this one:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');

But not working!

  • This is your custom template Magento_Catalog/template/view/my_custom_template.phtml? Where is the layout xml? – Khoa TruongDinh Mar 1 '17 at 13:22
  • what is the block class you are using to render the template? – Marius Mar 1 '17 at 13:22
  • it is a paid theme... I've created a child theme ... and created a custom template... prntscr.com/eepvjk – Fozia Zahoor Mar 1 '17 at 16:00

Use block class Magento\Catalog\Block\Product\View for render your phtml file.

You can get product Id by below code


extend or use block class


Get product using $block->getProduct() in your phtml file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.