Skip to content

Instantly share code, notes, and snippets.

@siaeb
Last active February 12, 2023 08:40
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siaeb/d0a238fc3ba4060bf4201ce582bb332d to your computer and use it in GitHub Desktop.
Save siaeb/d0a238fc3ba4060bf4201ce582bb332d to your computer and use it in GitHub Desktop.
Restrict WooCommerce Scripts
function woo_scripts_cleaner() {
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
$woo_styles = [
'woocommerce_frontend_styles',
'woocommerce-general',
'woocommerce-layout',
'woocommerce-smallscreen',
'woocommerce_fancybox_styles',
'woocommerce_chosen_styles',
'woocommerce_prettyPhoto_css',
'select2'
];
$woo_scripts = [
'wc-add-payment-method',
'wc-lost-password',
'wc_price_slider',
'wc-single-product',
'wc-add-to-cart',
'wc-cart-fragments',
'wc-credit-card-form',
'wc-checkout',
'wc-add-to-cart-variation',
'wc-single-product',
'wc-cart',
'wc-chosen',
'woocommerce',
'prettyPhoto',
'prettyPhoto-init',
'jquery-blockui',
'jquery-placeholder',
'jquery-payment',
'jqueryui',
'fancybox',
'wcqi-js',
];
// Dequeue Styles
foreach ( $woo_styles as $style ) {
wp_dequeue_style( $style );
}
// Dequeue scripts
foreach ( $woo_scripts as $script ) {
wp_dequeue_script( $script );
}
}
}
add_action( 'wp_enqueue_scripts', 'woo_scripts_cleaner', 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment