• Good morning,

    I am using your plugin ‘YITH WooCommerce Wishlist’ in the free version and have reworked the code published on WordPress Support as follows:

    if ( defined( 'YITH_WCWL' ) && ! function_exists( 'yith_wcwl_get_items_count' ) ) {
    function yith_wcwl_get_items_count() {
    $count = yith_wcwl_count_all_products();
    $output = '<div class="wishlist-button">';
    $output .= '<a href="' . esc_url( YITH_WCWL()->get_wishlist_url() ) . '" title="Wishlist" aria-label="Wishlist">';
    $output .= '<span class="yith-wcwl-items-count">';
    $output .= '<i class="yith-wcwl-icon fa fa-heart"><span class="counter' . ($count > 0 ? ' has-items' : '') . '">' . ($count > 0 ? esc_html( $count ) : '') . '</span></i>';
    $output .= '</span>';
    $output .= '</a>';
    $output .= '</div>';
    return $output;
    }

    add_shortcode( 'yith_wcwl_items_count', 'yith_wcwl_get_items_count' );
    }

    if ( defined( 'YITH_WCWL' ) && ! function_exists( 'yith_wcwl_ajax_update_count' ) ) {
    function yith_wcwl_ajax_update_count() {
    wp_send_json( array(
    'count' => yith_wcwl_count_all_products()
    ) );
    }

    add_action( 'wp_ajax_yith_wcwl_update_wishlist_count', 'yith_wcwl_ajax_update_count' );
    add_action( 'wp_ajax_nopriv_yith_wcwl_update_wishlist_count', 'yith_wcwl_ajax_update_count' );
    }

    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 ) {
    var counter = $('.yith-wcwl-items-count').find('.counter');
    if (data.count > 0) {
    counter.addClass('has-items').html(data.count);
    } else {
    counter.removeClass('has-items').html('');
    }
    } );
    } );
    } );
    "
    );
    }

    add_action( 'wp_enqueue_scripts', 'yith_wcwl_enqueue_custom_script', 20 );
    }

    I was able to get a perfectly functioning counter button on all pages of the site, but with the update to version 4.0.0 of the plugin, the counter only works dynamically within the wishlist page, generating the following error when removing items:

    XHRGET
    https://www.stagingene.netsons.org/wp-json/yith/wishlist/v1/products/?_locale=user
    [HTTP/3 400 1981ms]

    I have attempted various approaches to make the counter work on other pages, but without success. It seems that the added_to_wishlist event is not being triggered correctly, despite various attempts to monitor the click on the add buttons.

    Would it be possible to receive assistance on this issue? Any suggestions or alternative solutions would be greatly appreciated.

    Thank you in advance for your attention and support.

    Best regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi

    I would like to add that the same issue happens for my site and also what I see is that the counter does not work on the home page. then when I go to the wishlist it works and counter updates automatically. And if I remove the items from the list and go to the home page then the home page shows the counter with the same number of items that were already removed! so even an empty wishlist will constantly show a value. It all started after the latest update.

    Regards

    Plugin Support Juan Coronel

    (@juaancmendez)

    Hi there,
    thanks for contacting us!

    It is likely that with the new React implementations this code will not work correctly, so an adaptation would have to be created, which is not available at the moment.

    However, it is worth noting that the counter widget is a feature reserved for the premium version of the plugin.

    Best regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.