How to display the Wishlist contents on any page of the store?

Many store owners want to display the contents of Wishlist on selected pages of the store. In particular, we have received requests to display the wishlist contents at the following locations:

  • Account Page
  • Sidebar
  • Custom Popup
  • Footer

With the Smart Wishlist Public API, it has become possible to display the wishlist contents anywhere on the entire store. In this article, we shall explain how to do this. It assumes that the path to wishlist page is default /a/wishlist. If it has been changed, you need to replace it with the updated path.

1: Create an empty HTML <div>. Assign it a unique id.

2. Check if the user is logged in. If the user is logged in we shall display Express Wishlist, otherwise the User Account Wishlist shall be displayed.

3. Depending on the #2, make a AJAX request to the /a/wishlist endpoint using Smart Wishlist Public API.

4. Display the data received, in the <div> created above, using Javascript. Apply your own formatting.

For the starters, we have created a readymade code which can be embedded in any layouts/snippets/templates/sections of the theme to display the contents of wishlist. It may not work if you place it in any assets of the theme.

If you get the error, customerid not defined, add the following code to the above script,

var SWGetCustomerWishlistId=function()
{
	if((typeof __st)!=="undefined")
	{
	if(customer_id==undefined) customer_id=__st.cid;
	if(customer_id==undefined) customer_id=0;
	}
	
	return customer_id;
}

Leave a Reply

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