33

I am building Magento 2.0 only to sell 2 of my products online. The compare products and wishlist module is irrelevant for me.

How I safely and easily remove those modules? I dont want to hack the core code.

15 Answers 15

52

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>
  • Worked like a charm. Magento 2.0.6 – camdixon Jun 17 '16 at 16:00
  • FYI, here's the exact location of the instructions: devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/… – thdoan Jun 24 '16 at 9:12
  • 11
    Its not working in version 2.1.X – Jai Dec 12 '16 at 6:57
  • What about removing the My Wish List block? – Razvan Zamfir Oct 25 '17 at 16:48
  • You can add this to remove the wishlist block from the sidebar: <referenceBlock name="wishlist_sidebar" remove="true" /> – Frank Apr 6 '18 at 10:49
32

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"/>
  • 5
    Great answer, you also need to add <referenceBlock name="category.product.addto.compare" remove="true"/> to remove link from catalog product list. – Denis Pshenov Aug 20 '17 at 17:53
  • Thanks for your answer, you've missed to add also <referenceBlock name="catalogsearch.product.addto.compare" remove="true"/> that removes the compare function also from catalog search results. – Cristiano Casciotti Apr 10 at 8:12
  • Thank you @Devtype – Praveen Chelumalla Aug 28 at 1:24
12

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>
  • This works perfectly without having to modify any source files that could change in future updates. – PedroKTFC Mar 6 at 17:16
  • This should go into default.xml of a custom theme right? – Daniel Black May 29 at 15:53
5

Disable Wishlist on Stores > Configuration > Customers > Wishlist and to disable the Compare function paste this lines below on Magento_Catalog/layout/default.xml of your theme.

<?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="catalog.compare.link" remove="true"/>
        <referenceBlock name="catalog.compare.sidebar" remove="true"/>
    </body>
</page>

Set $showCompare to false in the following templates:

Magento/Catalog/view/frontend/templates/product/list/items.phtml Magento/Catalog/view/frontend/templates/product/widget/new/content/new_grid.phtml Magento/Catalog/view/frontend/templates/product/widget/new/content/new_list.phtml Magento/Catalog/view/frontend/templates/product/widget/content/grid.phtml

Remove compare related staff from the following templates:

Magento/Catalog/view/frontend/templates/product/list.phtml Magento/Catalog/view/frontend/templates/product/listing.phtml Magento/Wishslist/view/frontend/templates/item/configure/addto.phtml

Reference: https://coderwall.com/p/vsqmbw/remove-product-compare-functionality-on-magento-2-frontend

  • As of 2.1.x this solution is probably the most well put together. – themanwhoknowstheman Feb 14 '17 at 16:08
4

Magento provide command line utility for it example

php bin/magento module:disable -f Magento_Wishlist

as Magento wishlist depend upon the other module as well so using without [-f] will not disable or enable the module and will display warning like

enter image description here

after using command with [-f] flag will solve this issue

enter image description here

please check the warning when you are using command forcefully

Alert: You used the --force option. As a result, modules might not function properly.

You may check complete information here as well http://devdocs.magento.com/guides/v2.0/install-gde/install/cli/install-cli-subcommands-enable.html#instgde-cli-subcommands-enable-modules

  • Thanks. Your answer looks promising but I am bit nervous... Will this not break any other functionality? – Malaiselvan Jan 13 '16 at 17:19
  • You can try the same in Test Instance , it should not brake mainly permission will change that need to be altered – webkul Jan 13 '16 at 17:38
4

It can be disabled from

store > Configurations > Customers > Wish List> General options> Enabled: No.

4

UPDATE: After a Magento 2 core update, klara's answer is now the best way to disable Compare functionality. Please read below !

To disable Wish List functionality, you need to go in the administration, under Stores > Configuration > Customers > Wish List and choose Enabled : No.

To disable Compare functionality, there's no option in the administration. You need to override the module-catalog/view/frontend/templates/product/list.phtml template.

To do so, you need to copy the content of the file I named above in a new file inside your theme located under <theme_dir>/Magento_Catalog/templates/product/list.phtml. Then, you want to remove the concerned lines :

<?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>

Those are at lines 111 to 121 in Magento 2.0.1

3

to disable the sidebar:

<body>
  <referenceBlock name="catalog.compare.sidebar" remove="true"/>
</body>

to remove the "Add to compare" link on the product page you need to overwrite the Magento_Catalog/templates/product/view/addto.phtml file in your theme and remove the compare anchor there. This way you can keep the wishlist but remove the compare functionality.

3

For Magento 2.1.x

Adding a default.xml file to your theme in: /Magento_Catalog/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>
        <referenceBlock name="category.product.addto.compare" remove="true"/>
        <referenceBlock name="catalog.compare.sidebar" remove="true"/>
    </body>
</page>
  • add also <referenceBlock name="catalog.compare.link" remove="true"/> to remove link in top menu – عارف بن الأزرق Sep 29 '17 at 4:39
3

This is an extension of other solutions provided here. Use the file /app/design/frontend/Vendor/theme/Magento_Theme/layout/default.xml and add the following

<?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="catalog.compare.sidebar" remove="true"/>
    <referenceBlock name="catalog.compare.link" remove="true"/>
    <referenceBlock name="related.product.addto.compare" remove="true"/>
    <referenceBlock name="view.addto.compare" remove="true"/>
    <referenceBlock name="upsell.product.addto.compare" remove="true"/>
    </body>
</page>
1

You can add the line: <referenceBlock name="catalog.compare.sidebar" remove="true"/> Magento -> administrator -> PRODUCTS -> Categories -> Custom Design -> Custom Layout Update

0

After trying all the above methods for the individual product pages, I found the one file that mattered in my case, with an installed theme, but utilizing my own child theme addtocart.phtml. Other options will work for the grid category view and list category view (the aforementioned list.phtml, but on individual product pages:

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

This needs to be commented out. Hours and hours of trying and it was this file.

If anyone finds otherwise, please let me know!

  • find a solution.i l think my answer is best practice – Goldy Apr 6 '17 at 7:40
0

M2.1 quick and easy solution.
If you don't want to create a custom theme and/or prefer to work from the backend, you can do the following in the backend. Navigate to the cms page, category or product page you want to alter. Example for Category Page: under Design -> Layout Update XML add the following code:

<referenceContainer name="content">
    <referenceBlock name="catalog.compare.sidebar" remove="true" />
    <referenceContainer name="sidebar.additional" remove="true" />
 </referenceContainer>

Note: if you want additional blocks to remain in the sidebar, set the additional container to "false" like this:

 <referenceContainer name="content">
     <referenceContainer name="sidebar.additional" remove="false" />
 </referenceContainer> 
0

The wish list can be disabled via backend, as written in other answers.

There is a FOSS module which can remove the compare function on a per-store-view level:

https://github.com/Joshua29LK/disable-compare-magento-2

I did a short review:

  • It adds a layout handle to remove the compare blocks
  • This uses basically the same code as in the answers here (but is activated only on a store level)
  • The addto Link is removed by injecting CSS into the head, which sounds a bit strange but avoids replacing core templates
-2

You can use this paid module to disable compare in magento 2 ($20).
http://www.mage20.com/magento-2-disable-compare.html

Features:

  • No rewrite template
  • Just on config yes/no in system config.
  • Work fine on magento 2.x.

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.