1

I'm stuck on this:

I need to remove the SKU field from product page only for few products, I'm sure that I can do it with "layout update XML" tab but all my attempts have failed.. any help? :)

1

Try this solution.

You have to mention the block container name also

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

Here,product.info.stock.sku is the container name of your block.

<referenceContainer name="{CONTAINER_NAME_OF_BLOCK}">
       <referenceBlock name="{BLOCK_NAME_AT_LAYOUT}" remove="true" />
</referenceContainer>

If it not work then you can use the below solution also.

  • Create a new container

  • and Move your block to this container

  • After that remove container:

<container name="my.new.sections" htmlTag="div" />
<move element="product.info.sku" destination="my.new.sections" />
<referenceContainer name="my.new.sections" remove="true" />

Formula:

<container name="{New_Conatiner_Name}" htmlTag="div" />
<move element="{BLOCK_NAME_AT_LAYOUT}" destination="{New_Conatiner_Name}" />
<referenceContainer name="{New_Conatiner_Name}" remove="true" />
  • No one works :( I've tryed to add "<container name="my.new.sections" htmlTag="div" /> <move element="product.info.sku" destination="my.new.sections" /> <referenceContainer name="my.new.sections" remove="true" />" on layout update xml of an Item without success, I've tryed to add "<container name="my.new.sections" htmlTag="div" />" on catalog_product_view.xml and this code on layout update xml "<move element="product.info.stock.sku" destination="my.new.sections" /> <referenceContainer name="my.new.sections" remove="true" />" but still the same, SKU is showing as usual – Silver Jun 6 at 8:55
  • please ensure that your block name in layout is product.info.sku – Amit Bera Jun 6 at 8:58
  • Great, this one works: <referenceContainer name="product.info.stock.sku"> <referenceBlock name="product.info.sku" remove="true" /> </referenceContainer> Needs only a cach:clean after save! :P THANK YOU! – Silver Jun 6 at 9:13
  • Silly mistake was there:) – Amit Bera Jun 6 at 9:14
1
  1. Go to backend
  2. Select products that You need
  3. Edit attributes and choose layout update.

  4. Paste this:

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

and save

Update: Add reference container around referenceBlock

<referenceContainer name="your container ">

Ref:

https://inchoo.net/magento-2/bypassing-magento-2-layout-update-restrictions-admin/

  • I have already tried with this, but the result is an error on saving: Element 'referenceBlock': This element is not expected. Expected is one of ( referenceContainer, container, update, move, head, body ). Line: 1 – Silver Jun 5 at 21:56
  • Hmm This worked for all in product view xml.Maybe You could move this element only for this few products and hide it via css using specific classes. – BartZalas Jun 5 at 22:03
  • I update my answer. – BartZalas Jun 5 at 22:30
  • Still not working :( I've added this to my custom layout update xml: <referenceContainer name="content"> <container name="product.info.main"> <referenceBlock name="product.info.sku" remove="true" /> </container> </referenceContainer> – Silver Jun 6 at 9:03

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.