Skip to content

Wishlist JavaScript API for developers

Let your theme's own buttons, a quick view or another app read and change the shopper's wishlist on your store. Included on Free and Pro.

Updated

The wishlist script on your store has a JavaScript API. Your theme's own heart buttons, a quick view, a custom section or another app can use it to read and change the shopper's wishlist. It's part of the Wowsome Wishlist app embed, so there's nothing else to install.

The JavaScript API is included on Free and Pro. To read wishlists from your own tools instead, such as a CRM or a data warehouse, see Use the API and webhooks.

Methods

Everything is on window.WowsomeWishlist once the app embed has loaded.

MethodWhat it does
load()Fetches the shopper's list again and returns a promise with the items
items()Returns a copy of the saved items: product_id, variant_id, handle, title, image_url and price
has(productId)Says whether the product is saved
add(product)Saves a product. Does nothing if it's already saved
remove(productId, variantId)Removes a product. variantId is optional

add takes {id, handle, title, variantId, variantTitle, image, price}. id and handle are required, and price is text such as "35.00". The promise is rejected when the save isn't allowed, for example when the list is full, and the list on the page goes back to how it was.

The list is empty until it has loaded. Call load() to wait for it.

Hearts, the header counter and the wishlist page update by themselves. Your pixels get the same wishlist events as from the app's own buttons.

Know when the list changes

document.addEventListener("wowsome:wishlist:change", (event) => {
  const { action, product_id, count, items } = event.detail;
});

action is loaded, added or removed. The event fires as soon as the list changes on the page. If the save is then refused, a second event with the opposite action puts it back.

Example: your theme's own heart

<button type="button" class="my-heart" data-id="{{ product.id }}" data-handle="{{ product.handle }}">♡</button>
<script>
  document.addEventListener("click", (e) => {
    const b = e.target.closest(".my-heart");
    if (!b) return;
    const w = window.WowsomeWishlist;
    (w.has(b.dataset.id) ? w.remove(b.dataset.id) : w.add({ id: b.dataset.id, handle: b.dataset.handle }))
      .catch(() => alert("Couldn't update your wishlist"));
  });
  document.addEventListener("wowsome:wishlist:change", () => {
    document.querySelectorAll(".my-heart").forEach((b) => {
      b.setAttribute("aria-pressed", String(window.WowsomeWishlist.has(b.dataset.id)));
    });
  });
</script>

Without any script, a button with data-wishlist-toggle and data-product-id gets its pressed state from the app.

Still stuck? Write to hello@wowsome.app. We answer within one working day.