0

I'm trying to remove the compare products from appearing on the product page. We're a small publisher, and I'm not sure what compare would look like between two books in our catalog.

I'm currently using 2.3.6 and I've found in my searches a number of suggested modifications to the code that would supposedly remove this. However, many of them appear to be for earlier versions of Magento 2, and either the files are no longer named the same or the code changes do not work for the later version. Could anyone provide a code change for the compare items removal specifically for 2.3.6?

Thank you, Jeff

1 Answer 1

0

The easiest way to do this is to remove compare-related blocks from your layout.

If you share your earlier attempt we can see if something's wrong with it. It's hard to guess your skill level from your question.

In a nutshell:

  • Create a module YourName/YourModuleName/ , including registration.php and etc/module.xml. For now I'll assume you know how to do this.

  • Create layout update files. YourName/YourModuleName/view/frontend/layout/[somelayout].xml. The name of the file should be that of an existing layout you'd like to modify.

  • Add this in the contents to remove blocks. Magento will merge it with existing layout xml.

    <?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="[name of block to remove]" remove="true" />
            <referenceContainer name="[or maybe name of container to remove]" remove="true" />
        </body>
    </page>
  • To find out which blocks to remove and which layout names to use this will help you greatly. Use this command to find the layout xml files where blocks with names containing "compare" are included:

    egrep -r -i --include \*.xml --exclude-dir=var --exclude-dir=dev "<block".*?"name=" * | grep -I 'compare'

    To find out which other modules mess with those blocks use:

    egrep -r -i --include \*.xml --exclude-dir=var --exclude-dir=dev "<referenceBlock".*?"name=" * | grep -I 'compare'

  • Make sure to enable template hints on your development environment. It enables you to see which template files and blocks are used to display that content. It will not tell you the block names or file names, but it will help you understand the contents of the layout XML files you found using the grep commands.

2
  • Thank you. This is by far the clearest and most concise answer I've seen on this matter. Nov 12, 2020 at 21:29
  • And skill level is adequate. I can perform this type of coding, can upgrade version and add-ons, but I will probably hire someone to implement elasticsearch for me. Nov 12, 2020 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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