10

Can anybody please tell me how I can hide the SKU from the product page in Magento 2?

3 Answers 3

19

Create your own layout file for the product page:

 app\design\frontend\VENDOR\THEME\Magento_Catalog\layout\catalog_product_view.xml

Then, paste this code in the file:

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product.info.sku" remove="true" />
    </body>
</page>

This way, you can remove the SKU block without copying the whole file. Using the Layout remove attribute is also best practice!

7

The solution from MagentoOdoo.com won’t work since you can’t remove system attributes. Also if it did work, it would remove the attribute completely, and not just from the view.

To remove it just from the view, copy the following file:

vendor\magento\module-catalog\view\frontend\layout\catalog_product_view.xml

to your template folder, which should be something like this:

 app\design\frontend\**your_theme**\theme\Magento_Catalog\layout\catalog_product_view.xml

Then remove the following block of code (should be somewhere around line 36)

<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.sku" template="product/view/attribute.phtml" after="product.info.type">
  <arguments>
    <argument name="at_call" xsi:type="string">getSku</argument>
    <argument name="at_code" xsi:type="string">sku</argument>
    <argument name="css_class" xsi:type="string">sku</argument>
    <argument name="at_label" xsi:type="string">default</argument>
    <argument name="add_attribute" xsi:type="string">itemprop="sku"</argument>
  </arguments>
</block>

And replace it with:

<referenceBlock name="product.info.sku" remove="true"/>

clear the cache, and the SKU should be removed from the product view.

4
  • Ik heb precies gedaan hoe je hebt beschreven, maar SKU staat er nog steeds. Las dat dit ook een algemeen bekend probleem is, zie community.magento.com/t5/Magento-2-Feature-Requests-and/… Werkt het bij jou wel? Hoor graag van je, Kevin van der Toorn
    – Kevin
    Sep 14, 2016 at 17:07
  • Did you clear caches and reindex? Also check if the path where you copied the file to is correct. You can temporarily update the core file to see if that works. Sep 16, 2016 at 8:47
  • I made an exact copy of my theme (only editing the theme name in all files that contain the name), applied the new theme and it works. I have no idea why. Thanks for your answer and reply.
    – Kevin
    Sep 16, 2016 at 14:11
  • @kevin In plaats van dat je de code van het originele bestand kopieert naar je eigen bestand, probeer deze zin: <referenceBlock name="product.info.sku" remove="true" /> Mar 3, 2017 at 10:46
0

In your module create a layout named catalog_product_view.xml (No need for controller)

{venor_name}/{module_name}/view/frontend/layout/catalog_product_view.xml

Put this code

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product.info.sku" remove="true" />

    </body>
</page>

Flush the cache

Php bin/magento cache:flush

Hope it helps you.

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.