Hide shopping cart when empty

Hello how do we hide the woo commerce shopping cart when it’s empty?


I tried this , https://theme.co/apex/forums/topic/only-show-woocommerce-menu-cart-when-it-has-items/ but it didn’t seem to work

Hi There @Stigan

Thanks for writing in! Could you please provide us with the URL to your site, so that we can assist you accordingly.


Yes for, sure the URL and login for the site are in the secure note, thanks!

Hello @Stigan,

Thanks for sharing the details.

Please note that removing cart when it’s empty will require some custom development which falls outside the scope of support we offer. However, to help you get started you can use following code in child theme function.php file.

  function x_woocommerce_navbar_menu_item( $items, $args ) {

    if ( X_WOOCOMMERCE_IS_ACTIVE && x_get_option( 'x_woocommerce_header_menu_enable', '' ) == '1' ) {
      if ( $args->theme_location == 'primary' && WC()->cart->cart_contents_count > 0 ) {
        $items .= '<li class="menu-item current-menu-parent x-menu-item x-menu-item-woocommerce">'
                  . '<a href="' . x_get_cart_link() . '" class="x-btn-navbar-woocommerce">'
                    . x_woocommerce_navbar_cart()
                  . '</a>'
                . '</li>';

    return $items;

  add_filter( 'wp_nav_menu_items', 'x_woocommerce_navbar_menu_item', 9999, 2 );

Please note that beyond this any customization request will fall outside the scope of support we can offer.

If you would like to learn and get started with some WordPress development, please take a look at following resource.



This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.