Add a CSS class to an item when Woocommerce cart is empty
I am trying to hide my cart when it is empty, so I decided to add a CSS class to the cart HTML item when the cart is empty, here is my current code: function x_woocommerce_navbar_menu_item( $items, $args ) { if (WC()->cart->cart_contents_count == 0 ) { echo '<script type="text/javascript"> $(document).ready(function() { $("#header_cart").addClass("zero"); }); </script>'; } I am adding this to my functionts.php file Am I missing anything? It will be good if you add the class to body to make the hierarchy in CSS. Use the following code in functions.php : function tristup_body_classes( $classes )