In today’s tutorial, we will see how we can remove/disable add to compare functionality from all places in Magento 2.
There is no configuration setting to remove the “Product Compare” feature in Magento2.
But we can use the remove=”true” attribute in our theme’s custom layout file and remove/disable add to compare related reference blocks.
we can use the default.xml file to remove these links from all the pages in our theme.
for example,
app/design/frontend/vendor/theme/Magento_Theme/layout/default.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<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.link" remove="true"/>
<referenceBlock name="category.product.addto.compare" remove="true"/>
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="view.addto.compare" remove="true" />
<referenceBlock name="related.product.addto.compare" remove="true" />
<referenceBlock name="upsell.product.addto.compare" remove="true" />
<referenceBlock name="crosssell.product.addto.compare" remove="true" />
<referenceBlock name="catalogsearch.product.addto.compare" remove="true"/>
</body>
</page>
Also, you may need to make $showCompare variable value to “false” in all below .phtml files by overriding it in your custom theme.
vendor/magento/module-reports/view/frontend/templates/widget/viewed/content/viewed_grid.phtml:27: $showCompare = true;
vendor/magento/module-reports/view/frontend/templates/widget/viewed/content/viewed_list.phtml:28: $showCompare = true;
vendor/magento/module-reports/view/frontend/templates/widget/compared/content/compared_grid.phtml:23: $showCompare = true;
vendor/magento/module-reports/view/frontend/templates/widget/compared/content/compared_list.phtml:24: $showCompare = true;
vendor/magento/module-catalog/view/frontend/templates/product/widget/new/content/new_list.phtml:29: $showCompare = true;
vendor/magento/module-catalog/view/frontend/templates/product/widget/new/content/new_grid.phtml:27: $showCompare = true;
vendor/magento/module-page-builder/view/frontend/templates/catalog/product/widget/content/carousel.phtml:20: $showCompare = true;
vendor/magento/module-catalog-widget/view/frontend/templates/product/widget/content/grid.phtml:20: $showCompare = true;
You may also like :
How to Remove Blocks or Containers From Layout in Magento 2?
How to remove blocks programmatically in Magento 2?
That’s it for this tutorial, See you in the next blog. Thank You 🙂
Leave a Comment