William
William

Reputation: 13

Add a body class whole site when Woocommerce cart is empty

I'd like to add some description to product list when Woocommerce cart is empty and show/hide by css.

I've tried the following code from Add a CSS class to an item when Woocommerce cart is empty

function tristup_body_classes( $classes )
    {

        global $woocommerce;
        if( is_cart() && WC()->cart->cart_contents_count == 0){
            $classes[]='empty-cart';
        }
        return $classes;
    }
    add_filter( 'body_class', 'tristup_body_classes' );

It works fine, however the class is only added on cart page, I'd like it will be added on whole site, how should I do?

Upvotes: 1

Views: 759

Answers (1)

IncipientInfo
IncipientInfo

Reputation: 533

This class is added in only cart page because you checked the condition whether the page is cart page or not by using is_cart()

If you want to implement it in whole site, remove is_cart() from the if condition

change your condition to if( WC()->cart->cart_contents_count == 0)

Upvotes: 1

Related Questions