1

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

4
  • 1
    please attach screenshot where you want to disaply sku ?? – Rk Rathod Dec 11 '20 at 13:07
  • @RkRathod Image added – totneschap Dec 11 '20 at 13:59
  • please specify where you want to show SKU into attached screenshot – Msquare Dec 28 '20 at 10:37
  • @Msquare I have added the new image showing where I would like the sku. Like I said, the sku is already showing somewhere else on the page. – totneschap Jan 14 at 11:36
1

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>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.