Skip to content

Instantly share code, notes, and snippets.

@artikus11
Last active November 16, 2023 20:08
Show Gist options
  • Save artikus11/95fdfccbb70fa925afc96efbb11c92e0 to your computer and use it in GitHub Desktop.
Save artikus11/95fdfccbb70fa925afc96efbb11c92e0 to your computer and use it in GitHub Desktop.
Подключение скриптов и стилей только на страницах WooCommerce
/**
* Подключение скриптов и стилей только на страницах WooCommerce
*
* @testedwith WooCommerce 5.5
* @verphp 7.0
* @author Artem Abramovich
*/
function art_connection_css_js_only_woocommerce_pages() {
if ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) {
return;
}
$enqueues = [
'styles' => [
'woocommerce-inline',
'photoswipe',
'photoswipe-default-skin',
'select2',
'woocommerce_prettyPhoto_css',
'woocommerce-layout',
'woocommerce-smallscreen',
'woocommerce-general',
'wc-block-vendors-style',
'wc-block-style',
'wc-block-vendors-style',
'wc-block-style',
],
'scripts' => [
'flexslider',
'js-cookie',
'jquery-blockui',
'jquery-cookie',
'jquery-payment',
'photoswipe',
'photoswipe-ui-default',
'prettyPhoto',
'prettyPhoto-init',
'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',
'wc-blocks-middleware',
'wc-blocks',
'wc-blocks-registry',
'wc-vendors',
'wc-shared-context',
'wc-shared-hocs',
'wc-price-format',
],
];
foreach ( $enqueues as $key => $enqueue ) {
if ( 'scripts' === $key ) {
wp_dequeue_script( $enqueue );
}
if ( 'styles' === $key ) {
wp_dequeue_style( $enqueue );
}
}
}
add_action( 'wp_enqueue_scripts', 'art_connection_css_js_only_woocommerce_pages', 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment