0

I'm trying to add a custom text on the minicart icon on our site's header, when no product is on the cart.

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

What could be happening here? I heard there's something called "fragments" that could be interfering but I'm not sure where to look for it.

<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>
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Peanuts
  • 2,641
  • 6
  • 29
  • 34

1 Answers1

0

I'm not sure if it was a cache problem.

In any case, I added this to my functions.php (in addition to the avobe code, which is placed on header.php) and it is now working:

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;

        }



}
Peanuts
  • 2,641
  • 6
  • 29
  • 34
  • Excuse me mr. Peanuts, I couldn't find any contact information in your profile - Can you please revise your *chosen answer* selection from 11 years ago on [this question](https://stackoverflow.com/q/1373142/104380)? Thanks! – vsync Jun 14 '20 at 08:58