I found this script that allows me to show cart content total above the shopping cart icon within WooCommerce:
<a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf (_n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
If there are 100 items in my cart it shows 100.
What I really want is to display the count by item types. So if there are 50 t-shirts and 50 shorts, I want that 2 item types count to be displayed individually.
Does anyone knows how I can achieve this?
Thanks
This function is made to display the cart count for a specific product category:
You will paste the code above to the function.php file of your active child theme or theme.
For
"shorts"
category you will use it this way:cat_cart_count( "shorts" )
and will replaceWC()->cart->get_cart_contents_count()
.Customizing the snippet code with it for
"tshirts"
and"short"
categories:As the html tag class "cart-contents" is use by woocommerce refreshed cart fragments, you might need to rename it as explained in: Custom cart item counts by product category in Woocommerce 3
Last thing in our customized snippet code, you can customize-it your way adding some text or additional things… I have replace
"item(s)"
by the category name.