Magento 2: Safe and easiest way to disable Compare products & Wishlist Module
In Magento 2, you can actually now remove Compare products functionality via xml file.
Compare products block is defined in vendor/magento/module-catalog/view/frontend/layout/default.xml
and you can remove it by adding a default.xml
file to your theme in: <theme_dir>/Magento_Catalog/layout/default.xml
inside which you remove your block as following:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="wishlist_sidebar" remove="true" />
</body>
</page>
You can add following xml instruction to either your custom theme's default xml file which should be located at /app/design/frontend/Vendor/theme/Magento_Theme/layout/default.xml
or to Magento_Catalog/layout/default.xml
file in your custom theme:
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="view.addto.compare" remove="true" />
<referenceBlock name="view.addto.wishlist" remove="true" />
which gets rid of
- sidebar compare block
- compare block from product details page
- add to wishlist from product details page
To remove add to compare from category pages (catalog product list) use:
<referenceBlock name="category.product.addto.compare" remove="true"/>
I grepped the source for all compare blocks. For 2.3 this is the complete list. This will also remove the compare link from the header.
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<!-- Remove compare -->
<referenceBlock name="catalog.compare.link" remove="true" />
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="catalogsearch.product.addto.compare" remove="true"/>
<referenceBlock name="category.product.addto.compare" remove="true"/>
<referenceBlock name="crosssell.product.addto.compare" remove="true" />
<referenceBlock name="related.product.addto.compare" remove="true" />
<referenceBlock name="upsell.product.addto.compare" remove="true" />
<referenceBlock name="view.addto.compare" remove="true" />
</body>
</page>