Question

I'm trying to show the product sku in two different places on the product page. Is this possible and if so how can I do it?

The sku is currently further down the page but I would also like to display it in product.info.main section as shown in the screenshot.

enter image description here

Was it helpful?

Solution

Declare inside the catalog_product_view.xml of your theme inside Magento_Catalog\layout\catalog_product_view.xml

<referenceContainer name="content">
  <referenceContainer name="product.info.main">
       <block class="Magento\Catalog\Block\Product\View" name="product.info.additional.sku" template="Magento_Catalog::product/view/additional_sku.phtml" before="product.info.price"/>
   </referenceContainer>
</referenceContainer>

And phtml file inside \Magento_Catalog\templates\product\view\additional_sku.phtml

<?php

/**
 * Product view template
 *
 * @var $block \Magento\Catalog\Block\Product\View
 */

    $_product = $block->getCurrentProduct();
    $sku = $_product->getSku();


    ?>

<div class="product-info-additional-sku">
    <?php
            Echo "<p>".$sku."</p>";
                
    ?>
</div>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top