- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020
04:32 AM
01-29-2020
04:32 AM
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.
Labels:
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020
06:00 PM
02-18-2020
06:00 PM
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!
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020
02:41 AM
01-30-2020
02:41 AM
Re: Show sku code
Hi @simo_web778
Try the below code:
$_product = $block->getProduct(); echo $_product->getSku();
I hope it will help you!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020
04:22 AM
02-18-2020
04:22 AM
Re: Show sku code
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; ?>
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020
06:00 PM
02-18-2020
06:00 PM
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!