• Resolved Dariusz

    (@idarek)


    Hi,
    I am using below code to de-register unneeded woocommerce elements on non-woocommerce pages. All working well apart of prettyPhoto that despite below is still loaded on non-woo pages. Any advise?

    
    // WooCommerce - Remove scripts and styles on non-shop pages
    add_action( 'wp_enqueue_scripts', 'disable_woocommerce_loading_css_js' );
    
    function disable_woocommerce_loading_css_js() {
    
    	// Remove the generator tag
    	remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
    
    	// Check if WooCommerce plugin is active
    	if( function_exists( 'is_woocommerce' ) ){
    
    		// Check if it's any of WooCommerce page
    		if(! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
    
    			## Dequeue WooCommerce styles
    			wp_dequeue_style('woocommerce-layout');
    			wp_dequeue_style('woocommerce-general');
    			wp_dequeue_style('woocommerce-smallscreen');
    			wp_dequeue_style('woocommerce_prettyPhoto_css');
    
    			## Dequeue WooCommerce scripts
    			wp_dequeue_script('wc-cart-fragments');
    			wp_dequeue_script('woocommerce');
    			wp_dequeue_script('wc-add-to-cart');
    			wp_deregister_script( 'prettyPhoto-init' );
    			wp_dequeue_script( 'prettyPhoto-init' );
    			wp_deregister_script( 'prettyPhoto' );
    			wp_dequeue_script( 'prettyPhoto' );
    
    			wp_deregister_script( 'js-cookie' );
    			wp_dequeue_script( 'js-cookie' );
    		}
    	}
    }
    
    • This topic was modified 3 years, 6 months ago by Dariusz.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers.

    Hey @idarek,

    I was taking a quick look at the snippet you posted. It seems like this conditional will need to use OR instead of AND. Typically is_cart() and is_checkout() will be true on different pages. As long as one of these is false, the code inside won’t run.

    
    if(! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
    

    Maybe something like this:

    
    if(! is_woocommerce() || ! is_cart() || ! is_checkout() ) {
    
    Thread Starter Dariusz

    (@idarek)

    Thanks, but not making any difference. Still prettyPhoto is loaded on non-woocommerce pages.

    See waterfall here gtmetrix

    • This reply was modified 3 years, 6 months ago by Dariusz.
    Plugin Support Shohan Hossain Nabil – a11n

    (@sohanhossain)

    Hey there ??

    There hasn’t been much activity on this thread. If you do require more help with the actual coding, we’d recommend you hire a developer who can take a look at this, quote you for their services, and help you add this feature to your site. We’d recommend getting in touch with a web developer or one of the customization experts listed at?https://woocommerce.com/customizations/.

    Please kindly note that customization goes beyond the scope of support we are able to provide in this forum.

    Cheers.

    Thread Starter Dariusz

    (@idarek)

    No.

    Plugin Support Shohan Hossain Nabil – a11n

    (@sohanhossain)

    Hello @idarek,

    I am not sure, what you meant by ‘no’. Do you want us to keep this thread open for a while?

    Thread Starter Dariusz

    (@idarek)

    You can close it as don’t think I will get a support here apart of pointing to pay something to do something that should not be needed.

    As I think about it, WooCommerce is not great when used as a subpart of the main page as wasting resources of the whole website when they shall be only loaded where they are needed.

    It’s much better to rethink need to use WooCommerce altogether or splitting it into different WordPress installation.

    Hey @idarek,

    I took a closer look at the URL from the waterfall you linked to. The PrettyPhoto library is the one that is included with WooCommerce, however, I believe another plugin is the one calling it here. Look at this screenshot of the source code:

    The ID here matches a YITH plugin. It’s possible this is what’s calling this instance of PrettyPhoto and not the WooCommerce core. I could be wrong, but I believe PrettyPhoto is deprecated in the Woo core anyway. When I load up a fresh installation with dummy content, the site uses PhotoSwipe instead of PrettyPhoto.

    https://github.com/woocommerce/woocommerce/blob/8e45860732d9c4dd5cb1899c106c089717f19964/includes/class-wc-frontend-scripts.php#L209-L218

    See if you can disable this with all YITH plugins disabled. If it still gives trouble, then try disabling all plugins except for WooCommerce, clear all caches, and try again.

    Let us know what you find out.

    Thread Starter Dariusz

    (@idarek)

    Interesting, thank you.
    Will investigate from there over the week.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Unable to wp_dequeue_script prettyPhoto’ is closed to new replies.