WooCommerce enqueue style on shop page

584 Views Asked by At

I'm struggling to get a CSS file to load just on WooCommerce shop archive pages only.

Looking at the documentation I know there is a is_shop() tag.

So I would have thought

function kodr_scripts_styles() {
    if( is_shop() ) {
        wp_enqueue_style( 'wc-shop', get_template_directory_uri() . '/css/shop-only.css', 'all' );
    }
}
add_action( 'wp_enqueue_scripts', 'kodr_scripts_styles' );

Would work fine. But the file doesn't load. I know I can use is_woocommerce() but I don't want this file loading on all WC pages. Any ideas?

1

There are 1 best solutions below

6
On

Try out this code in your theme function.php:-

EDITED:-

function zillion_enqueue_style() {
     if( is_shop() || (is_archive() && is_woocommerce()) ) {
        wp_enqueue_style( 'wc-shop-only', get_template_directory_uri() . '/css/shop-only.css',array(), 'all' );
    }
}
add_action( 'wp_enqueue_scripts', 'zillion_enqueue_style' );