Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1104050
    Andrei
    Participant

    Hi,

    I would like to remove the ‘ITEMS’ text from the cart menu in the top menu.

    I would like it to look like in the attached image.

    My website is //sinestezic.com.

    Thank you.

    #1104541
    Prasant Rai
    Moderator

    Hello There,

    Thanks for writing in!

    Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released.

    Then add following code in child theme function.php file:

    
    /**
     * Filter to remove the word 'item'/'items' from WP Menu Cart
     */
    add_filter( 'wpmenucart_menu_item_a_content', 'wpmenucart_remove_items_caption', 10, 1 );
    function wpmenucart_remove_items_caption($menu_item_a_content) {
    	global $wpMenuCart;
    	$item_data = $wpMenuCart->shop->menu_item();
    	$item_text = sprintf(_n('%d item', '%d items', $item_data['cart_contents_count'], 'wpmenucart'), $item_data['cart_contents_count']);
    	$menu_item_a_content = str_replace( $item_text, $item_data['cart_contents_count'], $menu_item_a_content);
    	return $menu_item_a_content;
    }

    Thanks.

    #1106695
    Andrei
    Participant

    Thank you for your reply. I added it in the child theme’s functions.php and it doesn’t work.

    #1106714
    Rad
    Moderator

    Hi there,

    Would you mind providing your admin and FTP login credentials in private reply? I like to conduct some test.

    For the meantime, please try this

    /**
     * Filter to remove the word 'item'/'items' from WP Menu Cart
     */
    add_filter( 'wpmenucart_menu_item_a_content', 'wpmenucart_remove_items_caption', 10, 1 );
    function wpmenucart_remove_items_caption($menu_item_a_content) {
    	global $wpMenuCart;
    	$item_data = $wpMenuCart->shop->menu_item();
    	$item_text = sprintf(_n('%d', '%d', $item_data['cart_contents_count'], 'wpmenucart'), $item_data['cart_contents_count']);
    	$menu_item_a_content = str_replace( $item_text, $item_data['cart_contents_count'], $menu_item_a_content);
    	return $menu_item_a_content;
    }

    Thanks!

    #1106738
    Andrei
    Participant
    This reply has been marked as private.
    #1106900
    Rue Nel
    Moderator

    Hello There,

    Thanks for providing the information. Please use this code instead:

    // Remove "item" text in the cart menu
    // =============================================================================
    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="" aria-hidden="true"></i>',
        'total' => WC()->cart->get_cart_total(),
        'count' => sprintf( _n( '%d', '%d', 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;
    
    }
    // =============================================================================

    And before testing your site, you must clear your browser’s cache. It is best that you use Chrome’s incognito mode or private browsing mode in other browser when testing your site.

    Hope this helps.

    #1106957
    Andrei
    Participant

    It worked! Thank you very much! You are the best!

    #1107061
    Joao
    Moderator

    Glad to hear it,

    Let us know if you need further help.

    Joao

  • <script> jQuery(function($){ $("#no-reply-1104050 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>