• Hi there

    If I add a product to the cart, it displays the product number as a little number in the header.
    If I do the same but for the wishlist, the amount of products is not visible for the wishlist icon in the header.

    Could you let me know how to achieve that?

    I already tried adding the following code within functions.php but this did not work:

    $count = 0;
    if( function_exists( 'yith_wcwl_count_products' ) ){
    $count = yith_wcwl_count_products();
    }

    Thanks a lot

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Antonio La Rocca

    (@therock130)

    Hi there

    This will require you customize default header template
    Unfortunately, every theme is different on this side, and it would be better to ask theme’s support how to achive this

    On my side, I can suggest you a good article that will help you create a counter updated each time a product is added/removed from wishlist
    Once you add the code suggested in the article to functions.php of your theme, you’ll be able to use [yith_wcwl_items_count] shortcode in your header to show counter

    Anyway, when it comes to where to place it, as said before, you should rely on theme’s developers

    Thread Starter Michael Sutter

    (@michih)

    Hi Antonio

    Thanks a lot for your reply and the very helpful article.
    I followed the steps there, however, it says that it works with AJAX.

    I used this shortcode in the article but the amount of the products in the wishlist only refreshs after a page load (so for some reason not via AJAX).

    Do you have any hints how to implement it with AJAX so it does +1 instantly when adding a product to the wishlist?

    Besides that: the counter works great!

    Thanks again
    Michael

    Plugin Support Antonio La Rocca

    (@therock130)

    Hi again Michael

    The counter should be statically loaded when the page is first loaded, and then refreshed via ajax any time a product is added/removed from the list (so whenever the count of items change)
    To be more clear, the Add/Remove from wishlist action should be triggered from the same page the counter is in (it won’t constantly pool the system asking for current number of items in wishlist)

    Could you please share an url to the page where you placed the counter, so I can test it and see what is going wrong?

    Thread Starter Michael Sutter

    (@michih)

    Hi Antonio

    Thanks, I see.
    So if I understand you correctly, the counter should be loaded within header.php, correct? As it is needed on every page of the website.

    As mentioned in my initial post, I placed the code within functions.php (but this might be wrong for it to be refreshed instantly after adding a new product to the wishlist).

    You can also find the URL to the website in my initial post above.

    Thanks again, have a great day
    Michael

    Plugin Support Antonio La Rocca

    (@therock130)

    Sorry, didn’t get you already placed counter in the header of your site

    Anyway, I think I see the problem: as you changed a bit the HTML structure of the counter, also js will require some tweaking

    So, I suggest you to change this part of the article’s code

    if ( defined( 'YITH_WCWL' ) && ! function_exists( 'yith_wcwl_enqueue_custom_script' ) ) {
      function yith_wcwl_enqueue_custom_script() {
        wp_add_inline_script(
          'jquery-yith-wcwl',
          "
            jQuery( function( $ ) {
              $( document ).on( 'added_to_wishlist removed_from_wishlist', function() {
                $.get( yith_wcwl_l10n.ajax_url, {
                  action: 'yith_wcwl_update_wishlist_count'
                }, function( data ) {
                  $('.yith-wcwl-items-count').children('i').html( data.count );
                } );
              } );
            } );
          "
        );
      }
      add_action( 'wp_enqueue_scripts', 'yith_wcwl_enqueue_custom_script', 20 );
    }

    as follows:

    if ( defined( 'YITH_WCWL' ) && ! function_exists( 'yith_wcwl_enqueue_custom_script' ) ) {
      function yith_wcwl_enqueue_custom_script() {
        wp_add_inline_script(
          'jquery-yith-wcwl',
          "
            jQuery( function( $ ) {
              $( document ).on( 'added_to_wishlist removed_from_wishlist', function() {
                $.get( yith_wcwl_l10n.ajax_url, {
                  action: 'yith_wcwl_update_wishlist_count'
                }, function( data ) {
                  $('.yith-wcwl-items-count').children('strong').html( data.count );
                } );
              } ).trigger( 'added_to_wishlist' );
            } );
          "
        );
      }
      add_action( 'wp_enqueue_scripts', 'yith_wcwl_enqueue_custom_script', 20 );
    }
    Thread Starter Michael Sutter

    (@michih)

    Antonio, you rock!
    Thanks a lot, this slight change and adding the trigger did exactly what my goal was.

    Thanks again for the great support
    Michael

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Count icon not displayed for wishlist in header’ is closed to new replies.