• Resolved sirluiz

    (@sirluiz)


    Hello how are you? I hope well!

    How to hide icon counter if value is zero “0” (it’s empty)?

    For example:
    the counter above the heart icon has the following structure:

    < span class="count-number" >
    < ? php echo yith_wcwl_count_products() ; ?>
    < / span >

    I tried as follows:

    < ? php if( YITH_WCWL()->count_all_products() > 0 ) : ?>
    < span class="count-number" >
    < ? php echo yith_wcwl_count_products() ; ?>
    < / span >
    < ? php elseif; ? > 

    … but without good results.

    It’s working perfectly, I just want to know if I can add a “class” or another function that hides it when it’s empty.

    The complete code of theme: https://app.screencast.com/XdAsARSWQ9ZOk

    I use a child theme and …. Sorry for the amateurism, I’m just getting started.

    Thanks ^^
    Hugs.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Juan Coronel

    (@juaancmendez)

    Hello Hugs,
    we hope you’re doing well!

    The problem is that the function count_all_products() counts all the items of all the wishlists of your site, and what you should do is only count the one of the current user.

    Try the following:

    if ( ! empty( yith_wcwl_count_products() ) ) : ?>
    <span class="count-number">
    <?php echo yith_wcwl_count_products(); ?>
    </span>
    <?php endif; ?>

    Let us know any news, please.

    Best regards.

    Thread Starter sirluiz

    (@sirluiz)

    Hello!
    Great! It fit like a glove!

    I was trying this way but I was using:

    if ( ! empty(YITH_WCWL()->count_all_products() ) ) : ?>

    Then the palliative solution I did was to put:
    echo yith_wcwl_count_products()” inside the span class, example: “counter_’0‘ ” and in the css “.counter_0 { display: none; }” …. (counter_1 or more would not be affected).

    But your code is much prettier (and is already running) =D

    Thanks for the speed and accuracy! You are to be congratulated!

    Hugs!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to hide icon counter if value is zero “0” (is empty)?’ is closed to new replies.