Aleš Sýkora wrote

Dequeue WooCommerce JS and CSS

If you do not use default WooCommerce Photoswipe lightbox, flexslider and other libraries, you can dequeue them for faster loading of your site.

I am doing that especially when I use the Oxygen Builder because in most times I build my own product galleries with fancybox.

How to do Dequeue WooCommerce JavaScripts and CSS styles?

Create your new PHP script in your scripts organizer, code snippets plugin, advanced scripts etc. and put the code below in new snippet.

You can add the styles and scripts as you need. Here is a list of styles and scripts I have found yet:

ScriptStyle
‘flexslider’,
‘js-cookie’,
‘jquery-blockui’,
‘jquery-payment’,
‘photoswipe’ ,
‘photoswipe-ui-default’,
‘select2’,
‘selectWoo’,
‘wc-address-i18n’,
‘wc-add-payment-method’,
‘wc-cart’,
‘wc-cart-fragments’,
‘wc-checkout’,
‘wc-country-select’,
‘wc-credit-card-form’,
‘wc-add-to-cart’,
‘wc-add-to-cart-variation’,
‘wc-geolocation’,
‘wc-lost-password’,
‘wc-password-strength-meter’,
‘wc-single-product’,
‘woocommerce’,
‘zoom’,
‘prettyPhoto’
‘prettyPhoto-init’
‘photoswipe’,
‘photoswipe-default-skin’,
‘wc-block-style’,
‘woocommerce-layout’,
‘woocommerce-inline’,
‘woocommerce-smallscreen’,
‘woocommerce-general’,
‘select2’,
‘prettyPhoto’,
Do you know more WooCommerce JS and CSS to dequeue? Let me know in comments section below. Thanks!

The code below disable loading of photoswipe CSS and JS, Woocommerce block styles, flexslider JS and Zoom js.

<?php
add_action( 'wp_enqueue_scripts', 'twiki_dequeue_woocommerce_styles', 99 );
function twiki_dequeue_woocommerce_styles() {

// styles
        $dequeue_styles = array(
            'photoswipe',
            'photoswipe-default-skin',
            'wc-block-style',
        );
    
        foreach ( $dequeue_styles as $dstyles ) :
            wp_dequeue_style( $dstyles );
        endforeach;

// scripts

$dequeue_scripts = array(
            'flexslider',
            'photoswipe' ,
            'photoswipe-ui-default',
            'zoom',
        );
    
        foreach ( $dequeue_scripts as $dscripts ) :
            wp_dequeue_script( $dscripts );
        endforeach;
        
}

You can also use the official WooCommerce documentation to disable the WooCommerce stylesheets by recommended way to build own theme:

add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Auto-populate child content with parent content’s title
11. 7. 2019 in
Code snippet from our fan.
Read More
Aleš Sýkora wrote
Oxygen Lazy Load Gallery (Working 2021)
8. 4. 2020 in ,
Tutorial for working Lazy Load solution for Oxygen Builder gallery module.
Read More
Aleš Sýkora wrote
Oxygen Pro Menu Entire Parent Toggle Dropdown not working
22. 3. 2021 in ,
If you want to have your dropdowns shown in mobile menu with toggle, you are propably using Oxygen’s Pro menu option “Entire Parent Toggles Dropdown”. And it works fine, in most cases. But there is an issue with custom links. If your link uses # then this option doesn’t work. You need to use /# […]
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram