Sounds like this output is part of your theme – we don’t show a cart count by default.
Thread Starter
Jon
(@duffydjcoat)
Thanks Mike. I’ll try to sort that with them then.
Thread Starter
Jon
(@duffydjcoat)
Hi again Mike,
I’ve contacted the guys who created the template and they say didn’t change the behaviour at all of woocommerce.
I’ve got this as the code:
<?php
if (class_exists(‘Woocommerce’)) {
//Check if display cart in header
global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url();
$cart_count = $woocommerce->cart->cart_contents_count;
?>
<div class=”header_cart_wrapper”>
<div class=”cart_count”><?php echo esc_html($cart_count); ?></div>
“>
</div>
<?php
}
?>
Thanks
Exactly -if thats in your theme, it’s outputting the cart count, not WooCommerce. Wrap this in a check to see if cart_contents_count > 0.
Thread Starter
Jon
(@duffydjcoat)
Hi Mike,
Sorry, I’m lost here π
Where to I put that bit of code cart_contents_count > 0?
Thanks again!
Just to be clear this is part of your theme and the author should be doing a better job to support you.
Because that code is out of date and stinks, here is a better version which does what you need:
<?php
if ( class_exists( 'woocommerce' ) ) {
$cart_url = WC()->cart->get_cart_url();
$cart_count = WC()->cart->get_cart_contents_count();
if ( $cart_count > 0 ) {
echo '<div class="header_cart_wrapper">';
echo '<div class="cart_count">' . absint( $cart_count ) . '</div>';
echo '</div>';
}
}
Thread Starter
Jon
(@duffydjcoat)
Hi Mike,
Thanks a lot for the help. So, I’ve replaced the code I posted above with the new one you gave me, but that didn’t work. I can still see the zero in there…
Sorry, I’m not really a tech guy, how you might have already figured π
Thanks again and sorry to bother with this.
Can you share a link? The code I provided only outputs if $cart_count > 0.
Thread Starter
Jon
(@duffydjcoat)
Hi Mike,
Thanks for the reply. Unfortunately I can’t share the link as I’m still working on the site locally…
I guess it’s difficult for you to figure out what’s not working without a link..
Correct. Maybe this is also being output after ajax load. Theme may have some code in other places.
Thread Starter
Jon
(@duffydjcoat)
Thanks Mike. I’ll take it to them again! Thanks for the input. I’ll report back if I can find the solution