1

I want to remove Price block from specific product. I tried to updated Layout Update XML but it is not working

I have tried this <referenceBlock name="product.info.price" remove="true"/> but it do not work.

I read some where it will only accept the <referenceContainer>... not <referenceBlock name="block.name" remove="true"/>

So I tried

<container name="trash.bin" htmlTag="div" />
<move element="product.info.price" destination="trash.bin" />
<referenceContainer name="trash.bin" remove="true" />

this did not work either.Any solution?

  • 1
    magento.stackexchange.com/a/113932/54588 here is a creative solution ... – Manoj Deswal Sep 18 '17 at 6:41
  • @ManojDeswal as I mentioned I have tried this, but is not working. Please check my question last code snippet. I added the code and clean cache. – Arun Karnawat Sep 18 '17 at 6:52
  • If you can remove a price block with specific product, it is must create a new Block with product collection where you must specify your product or products and create a Helper with this Block, after that, you can create in Layout XML a new custom block where specify helper with "arguments" and in this Layout XML custom block, you can put the price block. In product collection, you can put the system configuration setings where specify from admin your product or products which no have a price. – St3phan Sep 18 '17 at 7:24
  • Blocks do support the remove function, see the dev docs for more info. – Ben Crook Sep 18 '17 at 9:42
3

I tested it on the Magento CE 2.1.7 and the layout update works fine. I've added the layout for the custom product (by its id) app/code/Vendor/Module/view/frontend/layout/catalog_product_view_id_2049.xml with the lines:

<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.price" remove="true"/>
    </body>
</page>

Here is product view page before the changes (having price block with a value 100$):

price block with a value 100$

After implementing the changes there is no price block at this place:

without price block

PS: tested on the Magento blank theme.

  • Thanks you, I have got the solution, I want to do it form Magento Admin From Layout Update XML andI have achieve that. But I am still accepting you answer as it is working too. and probability a better approach. but I need the functionary to be updated very frequently so I did it from Admin area. – Arun Karnawat Sep 18 '17 at 9:51

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.