Hi
i want to displayy sku code in product page
in "title.phtml"
app/design/frontend/theme/theme/Magento_Theme/templates/html
i put this :
echo "Sku : ". $block->getSku();
but is not working
Magento 2
Solved! Go to Solution.
Hi @simo_web778,
Got it, the previous code have not found product object in this file.
Try the below code.
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product echo $product->getSku(); ?>
I hope it will work for you!
Hi @simo_web778
Try the below code:
$_product = $block->getProduct(); echo $_product->getSku();
I hope it will help you!
thanks but is not workin
ERROR
Fatal error: Uncaught Error: Call to a member function getSku() on null
the code of titel.phtm is :
<?php $_product = $block->getProduct(); echo $_product->getSku(); ?> <?php echo $block->getChildHtml(); ?> </div> <?php endif; ?>
Hi @simo_web778,
Got it, the previous code have not found product object in this file.
Try the below code.
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product echo $product->getSku(); ?>
I hope it will work for you!