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 a helping hand in fixing your website issues?

If you are facing any problems in implementing these code snippets and tutorials, you can hire us to fix your website issues.

Hire Us