Callbacks and Functions

The app provides number of Javascript callback & functions which can be used for customised user experience development. The callbacks are already declared by us. In order to use them, you only need define them in your theme’s Javascript code. The functions are both declared as well as defined, so you just need to execute them.

(NOTE: This is an advanced feature meant for professional developers only.)

Callbacks triggered by click events on wishlist buttons

  • SWCallbackExpressWishlistProductItemAdded: It is triggered when a non-logged user adds an item to wishlist via an individual product page. It is triggered only for the primary product on that page. Secondary items such as Related Products or Recommended products are not catered by it.
  • SWCallbackExpressWishlistProductItemRemoved: It is triggered when a non-logged user removes an item from wishlist via an individual product page. It is triggered only for the primary product on that page. Secondary items such as Related Products or Recommended products are not catered by it.
  • SWCallbackExpressWishlistCollectionItemAdded: It is triggered when a non-logged user adds an item to wishlist via a collection/category page. It is also triggered when secondary items (such as Related Products) are added to wishlist via individual product page.
  • SWCallbackExpressWishlistCollectionItemRemoved: It is triggered when a non-logged user removes an item from wishlist via a collection/category page. It is also triggered when secondary items (such as Related Products) are removed from wishlist via individual product page.
  • SWCallbackCustomerWishlistProductItemAdded: It is triggered when a registered and logged-in user adds an item to wishlist via an individual product page. It is triggered only for the primary product on that page. Secondary items such as Related Products or Recommended products are not catered by it.
  • SWCallbackCustomerWishlistProductItemRemoved: It is triggered when a registered and logged-in user removes an item from wishlist via an individual product page. It is triggered only for the primary product on that page. Secondary items such as Related Products or Recommended products are not catered by it.
  • SWCallbackCustomerWishlistCollectionItemAdded: It is triggered when a registered and logged-in user adds an item to wishlist via a collection/category page. It is also triggered when secondary items (such as Related Products) are added to wishlist via individual product page.
  • SWCallbackCustomerWishlistCollectionItemRemoved: It is triggered when a registered and logged-in user removes an item from wishlist via a collection/category page. It is also triggered when secondary items (such as Related Products) are removed from wishlist via individual product page.

Callbacks triggered by the load events

  • SWCallbackWishlistButtonLoaded: This function is triggered when the wishlist button has loaded on a page. On pages where wishlist button has not been configured to be displayed, this function is triggered when the App’s script has been fired. Unlike the above functions, this function shall always be triggered across all pages, as long as the app is installed on the store. It can be used to make any changes to the Wishlist button dynamically.
  • WishlistLoadedCallback: This function is triggered when the items of wishlist page have fully loaded. It works for both logged-in and non-logged-in users. This function is triggered only on the default Wishlist page created by the App (e.g. /a/wishlist pages). However, it is not triggered on public wishlist pages (e.g. /a/wishlist/12444322xtssdgszasdadh pages

Function to reload Wishlist buttons

ReloadSmartWishlist: This function would trigger the app and populate the span and div containers with the HTML for wishlist button. This is mostly used when the products are loaded via AJAX. Calling this function adds wishlist button to such products.

It should be noted that unlike the above functions, this is not a callback function and therefore doesn’t need to be defined. It is already defined by the app and just needs to be called.

The safest and preferred way to call this function is as follows:

if (typeof ReloadSmartWishlist !== "undefined" && $.isFunction(ReloadSmartWishlist)) ReloadSmartWishlist();

Functions to interact with the Wishlist (Javascript API)

AddToSmartWishlist: This function can be used to add an item to wishlist. Both Express and Account Wishlists are supported.

RemoveFromSmartWishlist: This function can be used to remove an item from wishlist.

Usage:

AddToSmartWishlist(product_id,variant_id);

RemoveFromSmartWishlist(product_id,variant_id);

  • Here product_id and variant_id are numeric values generated by Shopify for each product/variant. it is upto you to ensure that correct values are passed to these functions.
  • These functions should be used in response to a user event only for e.g. a button click.

Leave a Reply

Your email address will not be published. Required fields are marked *