• Paul

    (@paulschiretz)


    Hi,

    I would like to replace the wishlist links(a tags) with real buttons.
    So far i managed to filter the html and output buttons. But the “a.tinvwl_add_to_wishlist_button” selectors in your js “function mark_products(data)” prevents the buttons to be marked as in the list. can we change them to be only selected by class(.tinvwl_add_to_wishlist_button)? I would really appreciate that!

    Proposed fix just removed the “a” from “a.tinvwl_add_to_wishlist_button”:

      /**
       * Marks products based on the provided data.
       *
       * @param {object} data - The data containing information about wishlists, products, and stats.
       */
      function mark_products(data) {
        var g = '1' == window.tinvwl_add_to_wishlist['simple_flow'];
        $('.tinvwl_add_to_wishlist_button').each(function () {
          $(this).removeClass('tinvwl-product-make-remove').removeClass('tinvwl-product-in-list').attr('data-tinv-wl-action', 'addto').attr('data-tinv-wl-list', '[]');
          if (data && data.stats) {
            $(this).find('span.tinvwl-product-stats').remove();
          }
        });
        $('body').trigger('tinvwl_wishlist_mark_products', [data]);
        $.each(data.products, function (i, item) {
          var id = i,
            e = $('.tinvwl_add_to_wishlist_button[data-tinv-wl-product="' + id + '"]');
          e.each(function () {
            var vid = parseInt($(this).attr('data-tinv-wl-productvariation')),
              vids = $(this).data('tinv-wl-productvariations') || [],
              j = false;
            for (var i in item) {
              if (item[i].hasOwnProperty('in') && Array.isArray(item[i].in) && (-1 < (item[i].in || []).indexOf(id) || -1 < (item[i].in || []).indexOf(vid) || vids.some(function (r) {
                return 0 <= (item[i].in || []).indexOf(r);
              }))) {
                j = true;
              }
            }
            $(this).attr('data-tinv-wl-list', JSON.stringify(item)).toggleClass('tinvwl-product-in-list', j).toggleClass('tinvwl-product-make-remove', j && g).attr('data-tinv-wl-action', j && g ? 'remove' : 'addto');
            $('body').trigger('tinvwl_wishlist_product_marked', [this, j]);
          });
        });
        if (data && data.stats && tinvwl_add_to_wishlist.stats) {
          $.each(data.stats, function (i, item) {
            var id = i,
              e = $('.tinvwl_add_to_wishlist_button[data-tinv-wl-product="' + id + '"]');
            e.each(function () {
              $(this).attr('data-tinv-wl-product-stats', JSON.stringify(item));
              var vid = parseInt($(this).attr('data-tinv-wl-productvariation')),
                j = false;
              for (var i in item) {
                if (-1 < i.indexOf(vid)) {
                  j = true;
                  $('body').trigger('tinvwl_wishlist_product_stats', [this, j]);
                  $(this).append('<span class="tinvwl-product-stats">' + item[i] + '</span>');
                }
              }
            });
          });
        }
        update_product_counter(data.counter);
      }

    All the best,
    Paul

  • The topic ‘Use a button for the wishlist button instead of a link’ is closed to new replies.