How to Disable Compare Products in Magento 2
Magento 2 offers a vast range of functionalities to make the most out of the platform. However, you may not need them all! It depends on the type of business and its requirements that you chose the features to include or not.
For example, there is a built-in feature to allow customers to compare the products. It is a very useful functionality if you are selling items like appliances, machines, software, etc for which the purchase decision depends on the features and price balance. In such cases, the customers need the “compare products” feature to check the feasibility.
However, if you are selling apparel, the purchase decision depends on the choice, liking, size availability, etc. and the customers do not need to compare two dress’ features, isn’t it!
Unfortunately, the default functionality does not allow to simply disable compare products in Magento 2. So, I’ve come up with a programmatic solution that allows to remove compare product functionality.
Method to Disable Compare Products in Magento 2:
Create default.xml file in Vendor/Extension/view/frontend/layout and copy the below code:
1 2 3 4 5 6 7 8 9 10 11 12 |
<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"/> <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> |
That’s it.
Any doubts?
Feel free to mention them in the Comments section below. I’d be happy to help.
Please share the above solution with the fellow developers via social media.
Thank you.
Facing issues with your Magento store or want to add new features? Our Magento Development Services are here to help!
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
6 Comments
how to remove compare product sidebar section from user account dashboard
Hello Mohd,
The code to remove compare product sidebar section is already there in the above solution.
Thank You
Hi, Im using 2.3 and the path doesn’t exist, so I’ve create it, and put the default.xml there but it seems is not working for me. there is something that I miss or Im doing some wrong?
Hello,
Create default.xml in the extension that you are using and place the above code file at view/frontend/layout extension.
Thank you.
This dosent remove add to compare button in case of following.
“Catlog Products List” widget placed on home page.
In above case the products of category selected in widget is displayed on home page. When you hover on the page Add to Compare button appears there. However if you click Category link to view products it dosent not appear.
Hello Ishant,
It seems as if a theme file is being called. You’ll need to remove the code from the file that is called.
Thanks.