"Hide empty cart" - No show even with items

I use the integrity stack and woocommerce.
Since I don´t want the cart to show when I don´t have any items in it I chose the “Hide empty cart” option.
But now it´s not showing at all.

Its showing in navbar if I don´t use that option, but all the time then.
The site is www.toppakropp.se/butik

Hello Martin,

Thanks for writing in! I can confirm that this is a bug in the recent update release. I already have informed our developers about this issue. A patch update will be out very soon.

Please bear with us. Cheers.

1 Like

Just so I know. Any idea when such a fix would go live? Are we talking weeks, years or months?

Hey Martin,

The developers has fixed the issue. The patch update release will be rolling out anytime soon.
Meanwhile, for a temporary fix, assuming that the child theme is set up, please add the following code in your child theme’s functions.php file

// Cart Menu Item
// --------------

if ( ! function_exists( 'x_woocommerce_navbar_menu_item' ) ) :
  function x_woocommerce_navbar_menu_item( $items, $args ) {

    if ( x_get_option( 'x_woocommerce_header_menu_enable' ) == '1' && did_action( 'x_classic_headers' ) ) {

      if ( x_get_option( 'x_woocommerce_header_hide_empty_cart' ) == '1' ) {

        if ( WC()->cart->get_cart_contents_count() > 0 ) {

          if ( $args->theme_location == 'primary' ) {
            $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>';
          }

        }
      } else {
        if ( $args->theme_location == 'primary' ) {
            $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 );
endif;

We would loved to know if this has work for you. Thank you.

Worked like a charm!
quick quesion to change to word “Item” in the cart showing in a menu to a diffrent language, do I do that in woocommerce or is that X theme?

Hi Martin,

You can change that through translation or add this code to child theme functions.php with your preferred text

  function x_woocommerce_navbar_cart() {

    $cart_info   = x_get_option( 'x_woocommerce_header_cart_info' );
    $cart_layout = x_get_option( 'x_woocommerce_header_cart_layout' );
    $cart_style  = x_get_option( 'x_woocommerce_header_cart_style' );
    $cart_outer  = x_get_option( 'x_woocommerce_header_cart_content_outer' );
    $cart_inner  = x_get_option( 'x_woocommerce_header_cart_content_inner' );

    $data = array(
      'icon'  => '<i class="x-icon-shopping-cart" data-x-icon-s="&#xf07a;" aria-hidden="true"></i>',
      'total' => WC()->cart->get_cart_total(),
      'count' => sprintf( _n( '%d Item', '%d Items', WC()->cart->cart_contents_count, '__x__' ), WC()->cart->cart_contents_count )
    );

    $modifiers = array(
      $cart_info,
      strpos( $cart_info, '-' ) === false ? 'inline' : $cart_layout,
      $cart_style
    );

    $cart_output = '<div class="x-cart ' . implode( ' ', $modifiers ) . '">';

      foreach ( explode( '-', $cart_info ) as $info ) {
        $key = ( $info == 'outer' ) ? $cart_outer : $cart_inner;
        $cart_output .= '<span class="' . $info . '">' . $data[$key] . '</span>';
      }

    $cart_output .= '</div>';

    return $cart_output;

  }

It’s in the line 'count' => sprintf( _n( '%d Item', '%d Items', WC()->cart->cart_contents_count, '__x__' ), WC()->cart->cart_contents_count )

Thanks!

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