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.

STEPS

1: Create an empty HTML container. Assign it a unique id wishlisthtml

HTML

2. In the Liquid, check if the user is logged in. If not, 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.

JavaScript

4. Display the data received, in the HTML container created in Step 1. Apply your own formatting.

JavaScript

For the starters, we have created a readymade code (based on Supply theme) 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.

HTML

Display Wishlist on My Account page

The following code has been adapted for displaying the wishlist on My Account page of your store.

HTML

MORE BUTTONS

You can also provide Add to Cart and Remove from Wishlist buttons to each items in the wishlist displayed here. This article explains the how-to in detail.

TROUBLESHOOTING

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

JavaScript

Leave a Reply

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