Custom Wishlist Implementation
Learn how to build custom wishlist functionality using Lantern's JavaScript API and metafields
For developers who want to build custom wishlist experiences beyond Lantern's built-in extensions, this guide shows you how to implement wishlist functionality using Lantern's JavaScript API and metafields.
Prerequisites
Before building custom wishlist functionality, ensure you have:
- Wishlists enabled in your Lantern app
- Basic knowledge of JavaScript and Liquid templating
- Access to your theme's code
Accessing Wishlist Data
Customer Metafields
Lantern stores wishlist data in customer metafields that you can access in your Liquid templates
customer.metafields.lantern.wishlist
- Array of product variant references in the customer's wishlist
JS API
Lantern also stores the wishlist data and functionality in the window.lantern
object. You can access it using the following methods:
window.lantern.wishlist
- Array of product variant references in the customer's wishlistwindow.lantern.api.toggleListItem
- Function to add or remove a product variant from the wishlist
Adding a Custom "Add to Wishlist" Button
To create your own button to add or remove a product variant from the wishlist, add the following code snippet to your theme's Liquid template:
Rendering Wishlist Items
Creating a Wishlist Section
Create a custom section template (sections/wishlist.liquid
) to display saved items using your themes built in product grid snippet (card-product
for a Dawn based theme, like in this example).