Home Forums Basel support forum Hide "0" in empty cart

Hide "0" in empty cart

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #15316

    Denisshishkin
    Participant

    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.

    #15318

    Artem Temos
    Keymaster

    Hello,

    Thank you so much purchasing our theme and contacting our support center.

    Try to add the following code snippet to the functions.php file in the child theme

    function basel_cart_count() {
    	if( WC()->cart->cart_contents_count == 0) return;
    	?>
    		<span class="basel-cart-number"><?php echo WC()->cart->cart_contents_count; ?></span>
    	<?php
    }

    Kind Regards
    XTemos Studio

    #15319

    Denisshishkin
    Participant

    Thanks, it works!
    Perhaps this code can be applied to the wish list as well?

    #15320

    Denisshishkin
    Participant

    And maybe you can add a different css class for an empty basket and for a basket with a value of 1 or more? Just now the value appears only after the page is updated… It would be cool if the figure appeared immediately after adding to the basket. I would add to the empty display: none, and to the full block

    #15322

    Artem Temos
    Keymaster

    Try this one

    function basel_header_block_cart() {
    	$position = basel_get_opt('cart_position');
    	$design = basel_get_opt('shopping_cart');
    	$extra_class = 'basel-cart-icon';
    
    	if(  basel_get_opt('shopping_icon_alt') ) {
    		$extra_class .= ' basel-cart-alt';
    	}
    
    	if( $position == 'side' ) {
    		$extra_class .= ' cart-widget-opener';
    	}
    
    	if( WC()->cart->cart_contents_count == 0 ){
    		$extra_class .= "empty-widget";
    	}
    	
    	if ( basel_woocommerce_installed() && $design != 'disable' ): ?>
    		<div class="shopping-cart basel-cart-design-<?php echo esc_attr( $design ); ?> <?php echo esc_attr( $extra_class ); ?>">
    			<a href="<?php echo esc_url(WC()->cart->get_cart_url()); ?>">
    				<span><?php esc_html_e('Cart', 'basel'); ?> (<span>o</span>)</span>
    				<span class="basel-cart-totals">
    					<?php basel_cart_count(); ?>
    					<span class="subtotal-divider">/</span> 
    					<?php basel_cart_subtotal(); ?>
    				</span>
    			</a>
    			<?php if ( $position != 'side'): ?>
    				<div class="dropdown-wrap-cat">
    					<div class="dropdown-cat">
    						 <?php 
    
    							// Insert cart widget placeholder - code in woocommerce.js will update this on page load
    							echo '<div class="widget woocommerce widget_shopping_cart"><div class="widget_shopping_cart_content"></div></div>';
    
    						  ?> 
    					</div>
    				</div>
    			<?php endif ?>
    		</div>
    	<?php endif;
    }

    And this code will hide wishlist

    	function basel_header_block_wishlist() {
    		if( YITH_WCWL()->count_products() == 0 ) return;
    		if ( basel_woocommerce_installed() && class_exists( 'YITH_WCWL' )  && basel_get_opt('header_wishlist') ): ?>
    			<div class="wishlist-info-widget">
    				<a href="<?php echo esc_url(YITH_WCWL()->get_wishlist_url()); ?>"><?php esc_html_e( 'Wishlist', 'basel' ) ?> <span><?php echo YITH_WCWL()->count_products(); ?></span></a>
    			</div>
    		<?php endif;
    	}

    Regards

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)