Wishlist Updated

An event that keeps an eye on wishlisted products of the app.

Description

The wishlistUpdated event triggers whenever a customer adds or removes products from their wishlist.

Function Signature

VajroSDK.listeners.onWishlistUpdated(() => {
// Write your logic
});
ParameterTypeRequiredDescription
NilNilNilThis listener does not require any parameter.

Example Usage

VajroSDK.listeners.onWishlistUpdated(() => {
  console.log('Wishlist updated:', VajroSDK.variables.customer.wishlistedProducts);
  //to display the number of products added to wishlist
document.getElementById("wishlist_count").innerHTML=JSON.stringify(VajroSDK.variables.customer.wishlistedProducts.length);
});

Best Practices

  1. Live badge updates: Use this event to keep the wishlist badge accurate without page reloads.
  2. Track engagement: Log wishlist add/remove events for marketing insights.
  3. Guard for logged-out users: Ensure the customer is logged in before performing wishlist actions.

Caveats

  1. Global event: Fires on any page where wishlist actions occur.
  2. Login dependency: Wishlist data is tied to the logged-in customer.
  3. API sync: Some delays may occur if wishlist data syncs asynchronously with Shopify.