Fix Conflict with YITH WooCommerce Zoom Magnifier

If you use the YITH WooCommerce Zoom Magnifier plugin, you may experience a conflict with JavaScript minification and LazyLoad. Here’s how to solve it.

Exclude JS-File from Minification

If you have enabled JS minification, you must exclude this file URL from minification:

/wp-content/plugins/yith-woocommerce-zoom-magnifier/assets/js/yith_magnifier.min.js

Disable LazyLoad for Variable Products

If the Zoom magnifier does not seem to work correctly for variable product images when LazyLoad is enabled, disable LazyLoad on those specific pages only. (This feature is available as of WP Rocket 2.5.)

Programatically Disable LazyLoad for Product Pages

In WP Rocket versions prior to 2.5 you must programatically disable LazyLoad for product pages with a custom MU plugin, or via functions.php.

Custom MU Plugin

Follow the general instructions in this article:
How to Make a Custom (MU) Plugin

1
Create a folder named mu-plugins in your wp-content folder.
In case a mu-plugins folder already exists, don’t create a new one, just use the existing one.
2
Using a basic text editor create a new file and put the following code in it:
<?php
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
/**
 * Plugin Name: WP Rocket | Disable LazyLoad for Single Products
 * Description: Programatically deactivates LazyLoad on WooCommerce single product pages.
 * Author:      WP Rocket Support Team
 * Author URI:  http://wp-rocket.me/
 * License:     GNU General Public License v3 or later
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */

/**
 * Disable LazyLoad on single product pages.
 * @return void
 */
function __deactivate_rocket_lazyload_if_page() {
	if( is_product() ) {
		add_filter( 'do_rocket_lazyload', '__return_false' );
	}
}
add_filter( 'wp', '__deactivate_rocket_lazyload_if_page' );
	
3
Save the file as wp-rocket-disable-lazyload.php
4
Upload this file to the mu-plugins folder created in step 1.
5
Finally, make sure to deactivate and re-activate WP Rocket.

From your Theme

Place the below snippet in the functions.php of your child theme or custom theme.

/**
 * Disable LazyLoad on single product pages.
 * @return void
 */
function __deactivate_rocket_lazyload_if_page() {
	if( is_product() ) {
		add_filter( 'do_rocket_lazyload', '__return_false' );
	}
}
add_filter( 'wp', '__deactivate_rocket_lazyload_if_page' );