Add class to body if WooCommerce cart has items


A very simple small snippet of code that will add a class to your site <body> tag, if the WooCommerce shopping cart has one or more items.

Add this to your functions.php file, within your theme or child-theme.

Replace ‘mytheme’ with the something to identify your own theme.
‘itemsInCart’ is the class that is added to your site, change this if you wish.

View the Gist:

Photo by: Jomjakkapat Parrueng on Unsplash