Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author James Koster

    (@jameskoster)

    Hi there,

    You can use the following if statement to check it the cart is empty;

    if ( sizeof( $woocommerce->cart->cart_contents ) == 0 ) {
    // The cart is empty
    }

    Thanks, Jay

    Thread Starter jimmierock

    (@jimmierock)

    Sorry for my stupidity I tried

    if ( sizeof( $woocommerce->cart->cart_contents ) == 0 ) {
    echo '<div class="' . $position . ' cart-tab no-animation ' . $skin . '">';
    } else {
    echo '<div class="' . $position . ' cart-tab ' . $skin . '">';
    					}

    and nothing happened.

    Is it possible for me to display Empty Cart when cart = 0?

    Plugin Author James Koster

    (@jameskoster)

    You’ve just wrapped the opening div in the statement, you should wrap the entire template in it ??

    Yes you could change the tab text to say the cart is empty. Again you will just need to add that if statement in the appropriate place.

    southamptonclimbingwall

    (@southamptonclimbingwall)

    Hi there,

    Sorry for not understanding this, where do I add the above code to stop the cart appearing when empty?

    Great plugin btw!

    Plugin Author James Koster

    (@jameskoster)

    @southamptonclimbingwall

    Take a look at the woocommerce_cart_tab() function in cart-tab.php. You need to wrap the contents of that function in the if statement from my original post.

    It won’t appear when products are added to the cart via ajax though remember.

    southamptonclimbingwall

    (@southamptonclimbingwall)

    Im really sorry but my coding skills are pretty limited, I’ve found the file you’re referring to and tried to “wrap” the function that you’ve mentioned.

    The problem for me now is not actually knowing where the function starts and ends and exactly what needs to be put in where. I realise that this is probably quite simple but would you perhaps be able to send the whole cart-tab.php with this edit already made?

    Sorry to be a pain, this is the perfect plugin for what we need but just have to hide it when empty so that it doesn’t disrupt mobile visitors who arent shopping.

    I hope you’re able to and dont mind doing this.

    many thanks,

    How is this resolved? I’ve wrapped the function in the new if statement and still get a cart tab when =0.

    Hi, You need to add

    if ( sizeof( $woocommerce->cart->cart_contents ) == 0 ) {
    // The cart is empty
    } else {

    before / above line

    ...
    if ( ! is_cart() && ! is_checkout() ) {

    and add }

    after / under line

    echo '</div>';
    ...

    It works for me ??

    Worked perfect for me.
    Really appreciate your help.
    Thanks a lot.

    Good God I’m an idiot… This whole time I kept forgetting to add the } else { statement!

    Arrrggg!!!

    Thanks azhkuro! Kudos to you!!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Make it hide with $0’ is closed to new replies.