bassjobsen / wp-defer-loading

Defer loading javascript for WordPress. Without any additional library. Just the way Google ask you to do it.
4 stars 2 forks source link

Woocommerce prettyphoto lightbox broken #14

Open bassjobsen opened 10 years ago

bassjobsen commented 10 years ago

When running the plugin with WooCommerce and the lightbox enabled the javascript is broken. The error: TypeError: e(...).prettyPhoto is not a function

bassjobsen commented 10 years ago

WooCommerce initiate two script to enable the lightbox in includes/class-wc-frontend-scripts.php:

    wp_enqueue_script( 'prettyPhoto', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js', array( 'jquery' ), '3.1.5', true );
        wp_enqueue_script( 'prettyPhoto-init', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );

prettyPhoto-init is not only dependent of jquery, but also of prettyPhoto. The dependency of prettyPhoto is not set.

Possible fix, add following code shown to your functions.php:

add_action( 'wp_enqueue_scripts', function() { global $wp_scripts; if ( ! empty( $wp_scripts->registered['prettyPhoto-init'] ) ) { $wp_scripts->registered['prettyPhoto-init']->deps=array('jquery','prettyPhoto'); } },99 );