Last active
June 29, 2025 01:43
-
-
Save loorlab/4cf5fa4614280715f6ae9f82aa163550 to your computer and use it in GitHub Desktop.
Disable WooCommerce - Exclude Pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// functions.php - Plugin | |
// Disable WooCommerce | |
function dw_conditional_woocommerce_assets() { | |
if (function_exists('is_woocommerce')) { | |
// Verifica si estamos en una página WooCommerce esencial | |
$is_woocommerce_page = is_woocommerce() || is_cart() || is_checkout() || is_account_page(); | |
// Handles específicos a remover si no estamos en una página WooCommerce | |
// styles | |
$styles_to_remove = [ | |
'woocommerce-general', | |
'woocommerce-layout', | |
'woocommerce-smallscreen', | |
'woocommerce-inline', | |
'ohio-woocommerce-style', | |
'brands-styles', | |
]; | |
// scripts | |
$scripts_to_remove = [ | |
'woocommerce', | |
'wc-add-to-cart', | |
'wc-cart-fragments', | |
'wc-checkout', | |
'wc-single-product', | |
'wc-add-to-cart-variation', | |
'jquery-blockui', | |
'jquery-placeholder', | |
'woocommerce-price-slider', | |
'fancybox', | |
'jquery-ui', | |
'wc-order-attribution', | |
'contact-form-7', | |
]; | |
// Si no es una página WooCommerce, desregistramos | |
if (!$is_woocommerce_page) { | |
foreach ($styles_to_remove as $style) { | |
wp_dequeue_style($style); | |
wp_deregister_style($style); | |
} | |
foreach ($scripts_to_remove as $script) { | |
wp_dequeue_script($script); | |
wp_deregister_script($script); | |
} | |
} | |
} | |
} | |
add_action('wp_enqueue_scripts', 'dw_conditional_woocommerce_assets', 99); | |
// Check Handles | |
/*add_action('wp_print_scripts', function () { | |
global $wp_scripts; | |
foreach ($wp_scripts->queue as $handle) { | |
echo "<p>Script cargado: {$handle}</p>"; | |
} | |
}); | |
add_action('wp_print_styles', function () { | |
global $wp_styles; | |
foreach ($wp_styles->queue as $handle) { | |
echo "<p>Estilo cargado: {$handle}</p>"; | |
} | |
});*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment