cancel
Showing results for 
Search instead for 
Did you mean: 

Show sku code

SOLVED
Highlighted

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
Highlighted

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!

----
Problem solved? Click Accept as Solution!

View solution in original post

3 REPLIES 3
Highlighted

Re: Show sku code

Hi @simo_web778 

 

Try the below code:

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

I hope it will help you!

----
Problem solved? Click Accept as Solution!
Highlighted

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

 

 

Highlighted

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!

----
Problem solved? Click Accept as Solution!

View solution in original post