• Resolved Jon

    (@duffydjcoat)


    Hi there. Is it possible to have the cart only showing the item count when there is a product in the cart? At the moment, on top of the cart icon it shows “0” (zero. Is it possible to change the behaviour, so that the cart only shows the item count if there is something in the cart?

    To be clear I don’t to hide the item count completely, but only when the cart has nothing on it.

    Many thanks.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    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

    Plugin Contributor Mike Jolley

    (@mikejolley)

    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!

    Plugin Contributor Mike Jolley

    (@mikejolley)

    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.

    Plugin Contributor Mike Jolley

    (@mikejolley)

    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..

    Plugin Contributor Mike Jolley

    (@mikejolley)

    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

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Remove zero from cart’ is closed to new replies.