• Resolved levke21

    (@levke21)


    Hi,

    It is possible that the [ti_wishlist_products_counter] counter counts the number of products on the wishlist from the currently displayed product list? For example: If I filter by an attribute and only 40 products remain of 300 product displayed, then the counter will count the number of items on the wishlist from these 40 products.

    Regards

    • This topic was modified 1 year ago by levke21.

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author templateinvaders

    (@templateinvaders)

    Hi @levke21

    By default, the [ti_wishlist_products_counter] shortcode counts the total number of products in the user’s wishlist, regardless of any current product list filtering or attributes applied. It doesn’t limit the count to products from a specific displayed product list or attribute filter.

    So, in the scenario you described, where you filter your product list by attributes and only 40 products remain visible out of 300, the counter will still count the total number of items on the entire wishlist, not just from the filtered 40 products.

    If you require a custom solution where the counter considers only products from the currently displayed list, that would involve some custom development tailored to your specific needs. Feel free to provide more details or specifications if you’re interested in pursuing such a solution, and we can discuss the possibilities further.

    Thread Starter levke21

    (@levke21)

    Hi,
    Thank you for the response, since then I have tried approaching the thing in several different ways. I concluded that without modifying the IT Wishlist plugin, perhaps reading the product identifiers from the “session file” would be a good solution for achieving my goal. I wrote a code for this (shown below) but it is probably incorrect, because it does not return the appropriate value.

    It would be best if I could somehow modify the original IT Wishlist code to work for me appropriately. I will gladly get a subscription if necessary to get sure help with this matter.

    I asked several developers in my environment, but no one could help me meaningfully with this. I hope you can. This feature is unique in itself, as I didn’t find any extension that could do this.

    The essence of the feature would be for the wishlist to be able to work as a “Collection or Collection” for those users who do not want to buy the product but have already purchased the product (possibly not from my webshop but from elsewhere). And they see this throughout the entire website with a concrete counter that can also be filtered by attributes.

    // Session file prefix
    $session_file_prefix = 'ti_wishlist_data_';
    // Session file suffix - this contains the blog id and URL
    $session_file_suffix = md5(get_current_blog_id() . '_' . get_site_url(get_current_blog_id(), '/') . get_template());
    // Full session file path
    $wishlist_data_file = WP_CONTENT_DIR . '/sessions/' .
    $session_file_prefix . $session_file_suffix . '.dat';
    // Check if the file exists
    if(file_exists($wishlist_data_file)) {
    // Decode the contents
    $session_data = unserialize(file_get_contents($session_file));
    // Check if the session data is empty
    if(empty($session_data)) {
    error_log('Empty session data');
    }
    error_log(print_r($session_data, true));
    // Check the products part
    if(!isset($session_data['products'])) {
    error_log('No products');
    }
    // Create an empty array
    
    $product_id = [];
    // Take out the products part
    $products = $session_data['products'];
    foreach($products as $key => $product){
    error_log("Product: $key");
    $product_id[] = array_keys($product)[0];
    }
    } else {
    error_log("Failed to load session file");
    // File does not exist or is not readable
    // handle the error
    }
    function my_collection_shortcode() {
    global $product_id;
    if(empty($product_id)) {
    $count = 'ures a globalis valtozo';
    } else {
    $count = count($product_id);
    }
    return 'Number of products: ' . $count;
    }
    add_shortcode('my_collection_shortcode', 'my_collection_shortcode');
    
    
    Thread Starter levke21

    (@levke21)

    Unfortunately I don’t think reading the session is a good idea.

    Perhaps you need to modify the code so that it requests the currently displayed products from the API instead. I tried to do this but it didn’t work. The code still seems to count in the original way. (public.js / pulblic.mini.js)

    // Get wishlist data from REST API.
    var tinvwl_products = [],
      tinvwl_counter = false;
    $('.wishlist_products_counter_number').each(function () {
      tinvwl_counter = true;
    });
    var get_data_ajax = function get_data_ajax(refresh) {
      var current_products = [];
      $('a.tinvwl_add_to_wishlist_button').each(function () {
        if ('undefined' !== $(this).data('tinv-wl-product') && $(this).data('tinv-wl-product')) {
          current_products.push($(this).data('tinv-wl-product'));
        }
      });
      if ((current_products.length > 0 || tinvwl_counter) && tinvwl_add_to_wishlist.user_interacted) {
        tinvwl_products = current_products;
        var data = {
          'tinvwl-action': 'get_data',
          'tinvwl-security': tinvwl_add_to_wishlist.nonce
        };
        if ('refresh' === refresh) {
          var form = $('div.tinv-wishlist.woocommerce.tinv-wishlist-clear form[data-tinvwl_sharekey]');
          if (form.length) {
            $('div.tinv-wishlist.woocommerce.tinv-wishlist-clear').block({
              message: null,
              overlayCSS: {
                background: '#fff',
                opacity: 0.6
              }
            });
            data['tinvwl-paged'] = form.data('tinvwl_paged');
            data['tinvwl-per-page'] = form.data('tinvwl_per_page');
            data['tinvwl-sharekey'] = form.data('tinvwl_sharekey');
          }
        }
        if (tinvwl_add_to_wishlist.wpml) {
          data.lang = tinvwl_add_to_wishlist.wpml;
        }
        if (tinvwl_add_to_wishlist.wpml_default) {
          data.lang_default = tinvwl_add_to_wishlist.wpml_default;
        }
        if (tinvwl_add_to_wishlist.stats) {
          data.stats = tinvwl_add_to_wishlist.stats;
        }
        $.ajax({
          url: tinvwl_add_to_wishlist.wc_ajax_url,
          method: 'POST',
          cache: false,
          data: data,
          beforeSend: function beforeSend(xhr) {
            xhr.setRequestHeader('X-WP-Nonce', tinvwl_add_to_wishlist.nonce);
          }
        }).done(function (response) {
          if ('refresh' === refresh) {
            $('div.tinv-wishlist.woocommerce.tinv-wishlist-clear').unblock();
            $(document.body).trigger('wc_fragment_refresh');
            $('div.tinv-wishlist.woocommerce.tinv-wishlist-clear').replaceWith(response.content);
            localStorage.setItem(hash_key + '_refresh', '');
          }
          if (response.wishlists_data) {
            set_hash(JSON.stringify(response.wishlists_data));
          }
          $('body').trigger('tinvwl_wishlist_ajax_response', [this, response]);
        });
      }
    };
    $.fn.tinvwl_get_wishlist_data = function (refresh) {
      if ('refresh' === refresh) {
        get_data_ajax(refresh);
        return;
      }
      if ($supports_html5_storage) {
        if ('undefined' !== typeof Cookies && Cookies.get('tinvwl_update_data') !== undefined) {
          Cookies.set('tinvwl_update_data', 0, {
            expires: -1
          });
          localStorage.setItem(hash_key, '');
        }
        if (localStorage.getItem(hash_key)) {
          var data = JSON.parse(localStorage.getItem(hash_key));
          if ('object' === _typeof(data) && null !== data && (data.hasOwnProperty('products') || data.hasOwnProperty('counter'))) {
            if (!data.hasOwnProperty('lang') && !tinvwl_add_to_wishlist.wpml || tinvwl_add_to_wishlist.wpml && data.lang === tinvwl_add_to_wishlist.wpml) {
              if ('undefined' !== typeof Cookies && Cookies.get('tinvwl_wishlists_data_counter') === undefined) {
                mark_products(data);
                return;
              }
              if ('undefined' !== typeof Cookies && Cookies.get('tinvwl_wishlists_data_counter') == data.counter && (!data.hasOwnProperty('stats_count') || Cookies.get('tinvwl_wishlists_data_stats') == data.stats_count)) {
                mark_products(data);
                return;
              }
            }
          }
        }
      }
      if (tinvwl_add_to_wishlist.block_ajax_wishlists_data) {
        setTimeout(function () {
          mark_products(data);
        }, 500);
        return;
      }
      get_data_ajax();
    };
    tinvwl_add_to_wishlist.user_interacted = false;
    $.fn.tinvwl_get_wishlist_data();
    $(document).one('click keydown scroll', function () {
      tinvwl_add_to_wishlist.user_interacted = true;
      $.fn.tinvwl_get_wishlist_data();
    });
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Wishlist of current products’ is closed to new replies.