How to remove "0" on cart

Hello,
How can I remove “0” on the cart icon when there’s no item in shopping cart? I would like to show the item numbers only when user adds items to the cart.

Thanks.

Hello there,

In order to achieve such that objective, please try to do the following steps:

  1. Add the following function to duplicate the cart menu and assign a specific class name while cart is empty

function sydney_nav_cart2 ( $items, $args ) {
    $swc_show_cart_menu = get_theme_mod('swc_show_cart_menu');
    if ( $swc_show_cart_menu ) {
        if ( $args -> theme_location == 'primary' ) {
            $class = '';
            if( WC()->cart->cart_contents_count == 0 ) {
              $class = 'cart-is-empty';
            }
            $items .= '<li class="nav-cart nav-cart2"><a class="cart-contents '.$class.'" href="' . WC()->cart->get_cart_url() . '"><i class="fa fa-shopping-cart"></i><span class="cart-amount">' . WC()->cart->cart_contents_count . '</span></a></li>';
        }
    }
    return $items;
}
add_filter( 'wp_nav_menu_items', 'sydney_nav_cart2', 9, 2 );

You can apply it to your site by adding it into your child theme’s functions.php file. Or, you can use the functionality plugin like Code Snippets without a child theme.

  1. You’ll need the following CSS code to hide the default cart menu and hide the “0” number when cart is empty.

.nav-cart {
  display: none;
}

.nav-cart2 {
  display: block;
}

.cart-is-empty .cart-amount {
  display: none;
}

Add it into Appearance > Customize > Additional CSS in your site dashboard.

Regards,
Kharis

Thanks, Kharis, but it did not remove “0” from the cart.

Hello there,

Thank you for the followup!

Please share your site URL here, so I can check to troubleshoot.

Regards,
Kharis