cancel
Showing results for 
Search instead for 
Did you mean: 

Show sku code

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Show sku code

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

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Show sku code

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!

View solution in original post

3 REPLIES 3

Re: Show sku code

Hi @simo_web778 

 

Try the below code:

$_product = $block->getProduct();
echo $_product->getSku();

I hope it will help you!

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; ?>

 

 

Re: Show sku code

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!