• Resolved Jan444

    (@ign2009)


    Hi, I’m trying to add a custom text on the minicart / cart widget when no products are on it.

    I tried this and it works for a second, but something inmediately replaces the custom text for a “0”…

    What could be happening here?

      <div class="header-cart-count">
        <?php
        if ( ! WC()->cart->is_empty() ) { 
          echo WC()->cart->get_cart_contents_count();
        }else{
          echo "SUPER COOL CUSTOM TEXT";
        }
        ?>
      </div>

    Thanks for your help,

    • This topic was modified 5 years ago by Jan444.
    • This topic was modified 5 years ago by Jan444.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Jan444

    (@ign2009)

    I’m not sure if it was a cache problem, it could be.

    The minicart requires the browser cache to be cleared (or it requires to add a new product to it) if you do html changes to overwrite it on a child theme.

    Now my code is working and it could be a cache issue as stated, or maybe this code, that I added to functions.php:

    
    function iconic_cart_count_fragments( $fragments ) {
        
        $fragments['div.header-cart-count'] = '<div class="header-cart-count">' . WC()->cart->get_cart_contents_count() . '</div>';
        
        return $fragments;
    	
        
    	if ( ! WC()->cart->is_empty() ) { 
    
    		$fragments['div.header-cart-count'] = '<div class="header-cart-count">' . WC()->cart->get_cart_contents_count() . '</div>';
    		
    		return $fragments;
    
    	}else{
    		
    		$fragments['div.header-cart-count'] = '<div class="header-cart-count">L</div>';
    		
    		return $fragments;
    		
    		}
    	
    
        
    }
    • This reply was modified 5 years ago by Jan444.
    • This reply was modified 5 years ago by Jan444.
    • This reply was modified 5 years ago by Jan444.
    • This reply was modified 5 years ago by Jan444.
    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    I’m glad to hear your code is now working and you were able to narrow down what the possible cause of the issue was!

    I’m going to mark this thread as resolved.
    If you have any further questions, please start a new thread.

    Have a wonderful day!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help with minicart’ is closed to new replies.