[Resolved] WooCommerce Show Cart In Primary Menu If Not Empty

Home Forums Support [Resolved] WooCommerce Show Cart In Primary Menu If Not Empty

Home Forums Support WooCommerce Show Cart In Primary Menu If Not Empty

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #521286
    Fahmi

    Hi!

    I need some help.

    How to show Cart in Primary Menu only if the cart not empty?

    Having Cart menu item there when it empty not really does anything. Therefore it would be nice to hide it when the cart is empty.

    Thank you.

    #521790
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Give this PHP a try:

    add_filter( 'generate_woocommerce_menu_item_location', 'tu_hide_empty_cart_icon' );
    function tu_hide_empty_cart_icon( $location ) {
        if ( class_exists( 'WooCommerce' ) && sizeof( WC()->cart->get_cart() ) > 0 ) {
            return $location;
        }
    
        return 'none';
    }

    Let me know πŸ™‚

    #521868
    Fahmi

    I am not sure why.
    But the code would work as intended when I remove class_exists( ‘WC’ ) &&.

    Now with your help, I got it working.

    Thank you Tom.

    #522122
    Tom
    Lead Developer
    Lead Developer

    You’re welcome!

    #535972
    Bertram

    Hi

    The above (also leaving out class_exists( β€˜WC’ ) &&) worked for me on desktop, however, the cart is not hiding on mobile when it’s empty.

    Is there a way to achieve the same function on mobile as well?

    TIA

    (Generate Press Premium 1.6)

    #536793
    Tom
    Lead Developer
    Lead Developer

    It should work everywhere. Can you link me to your site?

    #536886
    Bertram

    It’s a new website (WIP), so it’s currently in maintenance mode.

    I have created a subscriber login to acces:

    How it’s showing: https://imgur.com/PEIm3j2
    How I’d like it to look (cart disabled in customiser): https://imgur.com/GORYRZD
    My PHP code: https://imgur.com/PJBfBiV

    I’ve put the php code in ‘wp-head’ in GP hooks, I’m not sure if that is what’s causing the problem.

    #537216
    Tom
    Lead Developer
    Lead Developer

    Seems like a bug. I’ll get it fixed in the next version.

    Thank you!

    #537452
    Bertram

    Okay good to hear, thank you πŸ™‚

    #568982
    Kim

    Is this already working on mobile? Many thanks πŸ™‚

    #569250
    Tom
    Lead Developer
    Lead Developer

    Not yet – this fix will be in 1.6.3 πŸ™‚

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.