Remove compare functionality in Magento 1 and Magento 2

Removecompare functionality in Magento 1 and Magento 2

Thinking about ideas for tutorials we try to cover technical support issues that may be faced by our lovely customers. Commonly, they are coming up to get an assistance via helpdesk system immediately without browsing in Google.

Today we’re going to discuss a problem of disabling product comparison feature. We’ll explain how to remove Add to Compare button from every page of your website. You'll learn how to disable compare block from sidebar, category page or product page. We'll list all steps for different magento versions separately.

Also, we've got a good offer for you at the end of an article. It will be about how to disable the default Magento “Compare” functionality much faster.

So, no wasting time. Let’s go straight to the solution.

How to disable Magento 1 compare functionality

First important steps are:

  • Copy all files into your theme folder and make changes there.
  • We don't recommend to edit core Magento files to avoid losing the changes you've made after magento upgrade.

1. Remove right column compare block.

Open the app/design/frontend/base/default/layout/reports.xml and remove the following code.

<block type="reports/product_compared" before="right.permanent.callout" name="right.reports.product.compared" template="reports/product_compared.phtml" />

Open the app/design/frontend/base/default/layout/catalog.xml and remove the following code.

<block type="core/template" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>

You can also use another way to remove that block without editing and dublicating core xml files. Please create local.xml file in your theme folder app/design/frontend/<your_package>/<your_theme>/layout/local.xml:

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <default>
        <remove name="right.reports.product.compared" />
        <remove name="catalog.compare.sidebar" />
    </default>
</layout>

You still need to remove compare links from templates manually as will be shown in instruction points 2 and 3.

2. Remove Compare link from the product page.

Open the app/design/frontend/base/default/template/catalog/product/view/addto.phtml and remove the following code.

<?php
    $_compareUrl = $this->helper('catalog/product_compare')->getAddUrl($_product);
    ?>
<?php if($_compareUrl) : ?>
    <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>

3. Remove Compare link from product list page in two places for grid and list mode.

Open the app/design/frontend/base/default/template/catalog/product/list.phtml and remove the following code.

<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
    <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>

How to remove product comparison in Magento 2

First important steps are:

  • We don't recommend to edit core Magento files to avoid losing the changes you've made after magento upgrade.
  • Create new theme inheriting from Luma and make all modifications there.

1. Remove compare block from sidebar.

Open the app/code/Magento/Catalog/view/frontend/layout/default.xml and remove the following code.

<referenceContainer name="sidebar.additional">
    <block class="Magento\Framework\View\Element\Template" name="catalog.compare.sidebar"
           template="Magento_Catalog::product/compare/sidebar.phtml">
        <arguments>
            <argument name="jsLayout" xsi:type="array">
                <item name="components" xsi:type="array">
                    <item name="compareProducts" xsi:type="array">
                        <item name="component" xsi:type="string">Magento_Catalog/js/view/compare-products</item>
                    </item>
                </item>
            </argument>
        </arguments>
    </block>
</referenceContainer>

You can also use another way to remove that block without editing and duplicating core XML files. There is no local.xml in Magento 2, however you can remove blocks in inherited theme in Magento_Theme/layout/default.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>
        <referenceContainer name="sidebar.additional">
             <referenceBlock name="catalog.compare.sidebar" remove="true"/>
        </referenceContainer>
    </body>
</page>

You still need to remove compare links from templates manually as will be shown in instruction points 2,3 and 4.

2. Disable the Compare button on product list page.

Open the app/code/Magento/Catalog/view/frontend/templates/product/list.phtml and remove the following code.

<?php
   $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
   ?>
<a href="#"
   class="action tocompare"
   title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
   aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
   data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product); ?>'
   role="button">
    <span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
</a>

3. Disable the Compare button on product page.

Open the app/code/Magento/Catalog/view/frontend/templates/product/view/addto.phtml and remove the following code.

<a href="#" data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product);?>'
        data-role="add-to-links"
        class="action tocompare"><span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span></a>
        

4. Remove the Compare button in related, new, upsell, cross-sell and other product list blocks.

Open the following list of templates included Luma Magento 2 theme:

app\code\Magento\Catalog\view\frontend\templates\product\list\items.phtml
app\code\Magento\Catalog\view\frontend\templates\product\widget\new\content\new_grid.phtml
app\code\Magento\Catalog\view\frontend\templates\product\widget\new\content\new_list.phtml
app\code\Magento\CatalogWidget\view\frontend\templates\product\widget\content\grid.phtml
app\code\Magento\Reports\view\frontend\templates\widget\compared\content\compared_grid.phtml
app\code\Magento\Reports\view\frontend\templates\widget\compared\content\compared_list.phtml
app\code\Magento\Reports\view\frontend\templates\widget\viewed\content\viewed_grid.phtml
app\code\Magento\Reports\view\frontend\templates\widget\viewed\content\viewed_list.phtml

For each product list block please change

$showCompare = true;

to

$showCompare = false;

We hope this tutorial will help you. And as we promised, we're now going to look at the quick solution that will help you to:

  • hide default Magento “Compare” functionality
  • enable “alternative” Compare page design

Magento 2 Compare module is what we are about. It allows removing a compare functionality in Magento 2. Instead, the module offers you to improve a compare page design with:

  • Sticky header while scrolling
  • Sticky attributes columns
  • The display of all product attributes or just the products' differences

You can use these features in case you still want to keep comparison shopping at your store.

Please tell us what issues you’d like to be discussed next time. We'd appreciate if you would send us your ideas.

Popular Magento Themes & Extensions

7 thoughts on “Remove compare functionality in Magento 1 and Magento 2”

  • Chamath

    How do we override following file

    app\code\Magento\CatalogWidget\view\frontend\templates\product\widget\content\grid.phtml
    But I couldn't find that file there. I was under vendor folder as follows.

    vendor\magento\module-catalog-widget\view\frontend\templates\product\widget\content\grid.phtml

    I copied it in to my theme folder to override as follows.

    app\design\frontend\btg\\Magento_Catalog_Widget\templates\product\widget\content\grid.phtml

    But it not working. Is there any other way to do this?

    Reply
    • Chamath

      My fault
      Overridden path must be as follows

      app\design\frontend\btg\Magento_CatalogWidget\templates\product\widget\content\grid.phtml

      Issue was here - Magento_CatalogWidget. Earlier it was Magento_Catalog_Widget

      Reply
  • Coquelicot

    Hello i'm using Magento 2.1.7, i've removed the compare sidebar thx to this tutorial but when i go to app/code/Magento/Catalog/view/frontend/templates/product/list.phtml

    I can't find the code you say in my file.

    How to solve it ?

    Cordialy

    Reply
    • Roman B.

      Magento moved it into separate block.

      Now you need to open layout file:

      app/code/Magento/Catalog/view/frontend/layout/catalog_category_view.xml

      and comment lines 25-27:

      <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
      name="category.product.addto.compare" as="compare"
      template="Magento_Catalog::product/list/addto/compare.phtml"/>

      Reply
  • Sreenu

    what is url for wishlist in magento2 in default.xml

    Reply
Leave a Reply