WordPress   

Add a class to body when Woocommerce cart is empty

This code snippet can be used for adding custom class to body, when there are no products in Woocommerce cart. It comes handy when we need to apply custom design to empty cart page

//Add class to body when cart is empty
function rp_woo_empty_cart_classes( $classes ){
	global $woocommerce;
    if( is_cart() && WC()->cart->cart_contents_count == 0){
		$classes[] = 'woocommerce-cart-empty';
    }
    return $classes;
}
add_filter( 'body_class', 'rp_woo_empty_cart_classes' );
Need Professional Support for Your Website Problems?

Whether you're facing website issues or struggling with code implementation, our team is here to assist. Hire us to get your website back on track.

Hire Us