• Resolved adamparr01

    (@adamparr01)


    Hi,

    I’ve been trying for a while to hide the menu cart only when it’s empty. I don’t really know any coding but my developers suggested I ask you for the “CSS class set indicating the cart is empty or indicating it has a count on the element itself, or on a parent element”.

    I was hoping you could please help with this so that I can finalise this last change on my website. Ideally I’d like to hide the dividing lines above and below if possible too.

    Thanks in advance!
    Adam

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Senff – a11n

    (@senff)

    Hey @adamparr01

    The cart (or any parent) does not have a specific CSS class when it’s empty, so it’s not possible to use CSS code to hide it only when there are no items in it.

    For this, you will need either PHP code, or Javascript.

    Thread Starter adamparr01

    (@adamparr01)

    Thank you for explaining! Could you possibly suggest the necessary PHP to fix?

    Hi,

    I visited your website. The cart is hidden now when it’s empty. How did you do that?

    Thread Starter adamparr01

    (@adamparr01)

    @ief_dr I added the following PHP to custom-functions.php

    add_action(‘wp_head’, ‘hook_css’, 99999);
    function hook_css() {
    // If cart is empty hide the item count
    if(WC()->cart->is_empty())
    echo ‘<style type=”text/css”> .main-navigation .grimlock-woocommerce-navbar_nav_menu{display:none !important;}</style>’;
    }

    If you find the right element on yours hopefully it will work for you too.

    Hey @adamparr01 !

    Thank you for sharing the solution with the others!

    I’ll go ahead and close the forum thread for now, but please open a new one if you have any questions.

    Warm regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hide menu cart when empty’ is closed to new replies.