Back

How to Disable Compare Products for Magento 2

Magento 2 comes with a lot of beneficial traits but it really depends on the business if we are using them or not. In my experience, I haven’t encountered any client who actually used the compare functionality in their web stores but again it really depends on the business profile. 

Create a default.xml file in the below-given path:

app\design\frontend\Themes\Yourtheme\Magento_Catalog\layout\

and add the following code:

				
					<?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 data-rsssl=1>

<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" />

<script>class RocketElementorAnimation{constructor(){this.deviceMode=document.createElement("span"),this.deviceMode.id="elementor-device-mode",this.deviceMode.setAttribute("class","elementor-screen-only"),document.body.appendChild(this.deviceMode)}_detectAnimations(){let t=getComputedStyle(this.deviceMode,":after").content.replace(/"/g,"");this.animationSettingKeys=this._listAnimationSettingsKeys(t),document.querySelectorAll(".elementor-invisible[data-settings]").forEach(t=>{const e=t.getBoundingClientRect();if(e.bottom>=0&&e.top<=window.innerHeight)try{this._animateElement(t)}catch(t){}})}_animateElement(t){const e=JSON.parse(t.dataset.settings),i=e._animation_delay||e.animation_delay||0,n=e[this.animationSettingKeys.find(t=>e[t])];if("none"===n)return void t.classList.remove("elementor-invisible");t.classList.remove(n),this.currentAnimation&&t.classList.remove(this.currentAnimation),this.currentAnimation=n;let s=setTimeout(()=>{t.classList.remove("elementor-invisible"),t.classList.add("animated",n),this._removeAnimationSettings(t,e)},i);window.addEventListener("rocket-startLoading",function(){clearTimeout(s)})}_listAnimationSettingsKeys(t="mobile"){const e=[""];switch(t){case"mobile":e.unshift("_mobile");case"tablet":e.unshift("_tablet");case"desktop":e.unshift("_desktop")}const i=[];return["animation","_animation"].forEach(t=>{e.forEach(e=>{i.push(t+e)})}),i}_removeAnimationSettings(t,e){this._listAnimationSettingsKeys().forEach(t=>delete e[t]),t.dataset.settings=JSON.stringify(e)}static run(){const t=new RocketElementorAnimation;requestAnimationFrame(t._detectAnimations.bind(t))}}document.addEventListener("DOMContentLoaded",RocketElementorAnimation.run);</script></body>

</page>
				
			
Collaboration

Free consultation!
Share your project & explore possibilities.

We ignite creative sparks with passionate minds, transforming ideas into powerful brands that stand out. Our design gurus craft exceptional UI/UX experiences for a lasting impact.

We use cookies to give you the best experience. Cookie Policy