Add class to body if WooCommerce cart has items

Items in cart

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 child-theme or custom theme.
If you do not have a child-theme, or a custom theme, you could use a plugin such as Code Snippets.

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: https://gist.github.com/macgraphic/69976d6c79ca4e616af235b8c12bcb49

Photo by: Jomjakkapat Parrueng on Unsplash

Codeable Certified Expert, Mark Smallman of MacGraphic