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? 回答1: It will be good if you add the class to body to