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.
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>
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>
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
To remove add to compare from category pages (catalog product list) use:
<referenceBlock name="category.product.addto.compare" remove="true"/>
<referenceBlock name="category.product.addto.compare" remove="true"/>
to remove link from catalog product list.
Commented
Aug 20, 2017 at 17:53
<referenceBlock name="catalogsearch.product.addto.compare" remove="true"/>
that removes the compare function also from catalog search results.
Commented
Apr 10, 2019 at 8:12
Wishlist can be disabled from
store > Configurations > Customers > Wish List> General options> Enabled: No.
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
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
after using command with [-f] flag will solve this issue
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
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
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>
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.
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>
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!
You can add the line: <referenceBlock name="catalog.compare.sidebar" remove="true"/>
Magento -> administrator -> PRODUCTS -> Categories -> Custom Design -> Custom Layout Update
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>
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:
I am using the Ultimo theme on Magento 2.3.3. I couldn't disable the compare link from the theme's catalog_product_view.xml file as the settings are not coming from there but they are located in:
vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml
I went for the quick and dirty solution, simply removed the following:
<container name="product.info.social" label="Product social links container" htmlTag="div" htmlClass="product-social-links">
<block class="Magento\Catalog\Block\Product\View" name="product.info.addto" as="addto" template="Magento_Catalog::product/view/addto.phtml">
<block class="Magento\Catalog\Block\Product\View\AddTo\Compare" name="view.addto.compare" after="view.addto.wishlist"
template="Magento_Catalog::product/view/addto/compare.phtml" >
<arguments>
<argument name="addToCompareViewModel" xsi:type="object">Magento\Catalog\ViewModel\Product\Checker\AddToCompareAvailability</argument>
</arguments>
</block>
</block>
<block class="Magento\Catalog\Block\Product\View" name="product.info.mailto" template="Magento_Catalog::product/view/mailto.phtml"/>
</container>
The compare button is gone forever, however if you perform a Magento upgrade it will come back so it will need to be removed again.
For Compare this is correct https://magento.stackexchange.com/a/253236/15747
For Wishlist, you can simply disable the HTML output by adding "system > Websites > base > advanced > modules_disable_output" to etc/app/config.php
This method avoids dependency issues as the module remains active but the output is disabled.
Note: My example includes other features that are commonly disabled.
<?php
return [
'modules' => [
....
],
'system' => [
'websites' => [
'base' => [
'advanced' => [
'modules_disable_output' => [
'Magento_Downloadable' => 1,
'Magento_Review' => 1,
'Magento_Wishlist' => 1,
'Magento_SendFriend' => 1
]
]
]
]
]
];
See: https://devdocs.magento.com/guides/v2.3/config-guide/config/disable-module-output.html
Quick and dirty solution was to change the visibility of tocompare feature by appending the following in default.css
.tocompare{ visibility: hidden; }