Just wondering if anyone has any ideas on how to hide the WooCommerce mini-cart icon conditionally based on the contents of the cart? Essentially trying to hide it if the cart is empty and show it if any item is in the cart.
I’ve tried with conditions of the but couldn’t find anything that works.
Thanks for the reply, I had tried that and it didn’t work. My understanding is that {woo_cart_quantity} does not return the number of cart contents, it is meant to be used in a custom cart loop to “Render the input field to add/remove the product quantity inside of the cart.” see this page that mentions it
I did figure out a solution though, posting it here for all future viewers. Also if anyone with more knowledge is digging through this in the future, please let me know if there is a more elegant solution.
What ended up working was creating a custom PHP function and using the echo tag to set the display conditions. Followed the information on this academy page about dynamic data, in the “Advanced: Echo” section. Good video there that walks through the process:
Added this to functions.php
function get_total_cart_quantity() {
// Get the cart object
$cart = WC()->cart;
// Return the total quantity of items in the cart
return $cart->get_cart_contents_count();
}
Then set the Mini Cart’s display condition similar to the last reply but with the echo function Dynamic data → {echo:get_total_cart_quantity} > 0