Zid Docs
  1. Code Snippets
Zid Docs
  • Merchant API
    • Start Here 🚀
    • Overview to Zid Apps
    • Authorization
    • Responses
    • Webhooks
    • Rate Limiting
    • APIs
      • Orders
        • Update Order by ID
        • Get Order Credit Notes
        • Get Order by ID
        • List of Orders
      • Reverse Orders
        • Reverse Order Reasons
        • Create Reverse Orders
        • Create Reverse Orders Waybill
        • Add Reverse Order Reasons
      • Carts
        • Get Abandoned Cart Details
        • List Abandoned Carts
      • Products
        • Managing Products
          • Get a Product by ID
          • Retrieve a list of products
          • Create a new product
          • Update an existing product.
          • Bulk update of products using their IDs or SKUs
          • Delete a product.
          • Product Setting
          • List Product Reviews
        • Digital Vouchers
          • Product Vouchers
          • Order Voucher
          • Add Product Voucher
          • Import Vouchers
          • Export Vouchers
          • Update Product Voucher
          • Remove Product Voucher
        • Product Categories
          • Get Single Category Details
          • Get all categories
          • Create Store Category
          • Update a Store Category
          • Add a product to a certain category
          • Publish/Unpublish a Category
          • Detach Category from All Products
          • Remove Category from Product
        • Product Badge
          • Product Badge
        • Product Attributes
          • Get Product Attributes
          • Get Product Attributes
          • Retrieve a product attribute
          • Add a New Product Attribute
          • Add a New Product Attribute
          • Update a product attribute
          • Delete a product attribute
        • Product Attribute Presets
          • Get attribute presets
          • Create Attribute Preset
          • Update Attribute Preset
          • Delete an attribute preset
        • Product Customizations
          • Add Product Variants
          • Insert Custom Options to a Product
          • Insert Custom User-Input Fields to a Product
        • Product Manual Sorting
          • Set Custom Product Order
          • Reset the manual sorting of all products
        • Product Images
          • Get List of images of a product.
          • Add an image to a product
          • Update a product Image Order
          • Delete a product image
        • Product Notifications
          • Availability Notification Stats
          • Availability Notifications Settings
          • List Availability Notifications
          • Add Availability Notification
          • Save Availability Notifications Settings
          • Manually Send Availability Notification Email
          • Export Availability Notifications
        • Product Import
          • Email All Products to Store Owner
          • Import Products via CSV or xlsx File
        • Product Stock (Multi-Inventory)
          • Get Product Stock by ID
          • List Product Stocks
          • Add Product Stock
          • Update Single Product Stock
          • Bulk Update Product Stocks
        • Product Questions & Answers
          • Get Question
          • Get Answer
          • Get All Questions
          • List Question Answers
          • Create Question
          • Create Answer
          • Update Question
          • Update Answer
          • Delete Question
          • Delete Answer
        • Product Reviews
          • List Reviews
          • New Reviews Total
          • Change Review Status
          • Bulk Change all Review Statuses
          • Delete Review
          • Import Product Reviews
          • Reply to Review
          • Delete Reply
          • Update Reply to Review
        • Digital Products
          • Create Downloadable Product
          • Generate an Upload URL
          • Upload File to S3
          • Create Product Downloadables
          • Get Product Downloadables
          • Delete Product Downloadables
          • Get Store Downloadables
          • Create Store Downloadables
          • Delete Store Downloadables
      • Inventories
        • Get Store Location by ID
        • List Store Locations
        • Add a New Location
        • Update a Location by ID
        • Update Products Stock by Location ID
      • Shipping
        • List Store Delivery Options
        • Add Shipping Option
      • Marketing
        • Gift Cards
          • Get Store Settings
          • Add gift card to the cart
          • Update Store Settings
          • Upload gift card designs
          • Remove gift card from the cart
        • Coupons
          • Create a New Coupon
          • List Coupons
          • Get Coupon Details
          • Update Coupon
          • Delete Coupon
        • Bundle Offers
          • Retrieve all Bundle Offers
        • Loyalty Program
          • Customer Wallet
          • Customer Points
          • Loyalty Program Points per Order
          • Store Loyalty Status
          • Redemption Methods
          • Cashback Rules
          • Add Redemption to Cart
          • Remove Redemption from Cart
          • Info Page
          • Loyalty Program Activation
          • Loyalty Status
          • Set Points Expiration
          • Cashback Rule Method Update
          • Cashback Rule Method Update Status
          • Add Points Redemption Method
          • Update Points Redemption Method
          • Delete Points Redemption Method
          • Toggle Redemption Method Status
          • Show Loyalty Points Info for Specific Customer
          • Customer Profile
          • List Data
          • Customer Points History
          • Info Page - Managers
          • Update Info Page
          • Adjust Customer Points
      • Customers
        • List of Customers
        • Get Customer by ID
      • Store Settings
        • 📄 User Roles and Permissions
        • Get Manager's Profile
        • Get VAT Settings
        • List of Payment Method
      • Countries and Cities
        • Retrieve Store Operating Countries
        • Retrieve Cities by Country ID
        • Countries List
      • Webhook
        • List of Webhooks
        • Create a Webhook
        • Delete a Webhook by OriginalId
        • Delete a Webhook by Subscriber
    • Store Events
      • Order
      • Product
      • Abandoned Cart
      • Customer
      • Product Category
  • App API
    • Create your First App
    • Embedded Apps
    • App Scripts
    • App Events
    • App Subscription
      • Get Subscription Details
      • Update Usage-Based Charges
  • Themes
    • 🚨 Important Update: Zid Themes
    • Adding Video URL Feature to Third-Party Themes
    • Landing Page Development
    • Getting Started with Zid Themes
      • Introduction to Theme Development
      • Manage your Themes
      • Building Themes in Zid
      • Theme File Structure
      • Twig Syntax and Features
      • Zid Theme Packager
    • Templates
      • Layout
      • Home Page
      • Products
      • Cart
      • Store Language and Currency
    • Settings Schema
      • Text
      • Number
      • Text-Area
      • Select
      • Radio Buttons
      • Checkbox
      • Range
      • Color
      • Image
      • Product
      • Category
      • List
      • Fieldset
    • Code Snippets
      • Apple Pay Quick Checkout
      • Custom CSS Injection
      • Displaying the Store's Business Center Logo
      • Customizing Copyright Text
      • Store's Main Navigation Menu
      • Customer Wishlist
      • Products
        • Products Badges
        • Product Ratings
        • Remaining Product Stock
        • Sold Items Count
        • Product Filtration by Attributes
        • Grouped Products
        • Product Questions & Answers
        • Product Restock Notfication
      • SEO
        • Images alt text
        • Themes SEO Marketing Tags
      • Marketing
        • Metafields
        • Gift Feature
        • Loyalty Program
    • Zid Themes Library: API Integration
      • Products
      • Product Categories
      • Cart
      • Blog
      • Customer
      • Store Settings
    • Data Reference
      • Locals
      • Store
      • Cart
      • Product
      • Products List
      • Category
      • Categories List
      • Session
      • FAQs
      • Customer
      • Blogs
      • Page
      • Main Menu
      • Main Navigation Menu
      • Request
      • Orders
      • Addresses
      • Store Payment Methods
      • Store Shipping Methods
      • Store Banks
      • Asset URL
      • Header Meta Tags
      • Loyalty pogram Wallet
    • Themes CLI
      • CLI Authentication
      • Theme Create
      • Theme Package
      • Theme Update
      • Themes List
      • Theme Preview
  1. Code Snippets

Customer Wishlist

Enable the End customer to add products to their wishlist from the merchant’s catalog in order to buy those products later, saving the research effort for them and increasing merchant sales.

Activation Steps for Merchants#

There are no steps needed to be activated on a store; you just need to use a store subscribed to the Growth package or above.

Code Snippet Integration for Theme Partners#

To properly integrate Wishlist into the theme, you’ll need to add these into the appropriate theme files:

1. Product Card component and Product page:#

Insert the following in the template/products.twig and template/category.twig file:
You’ll need to create a variable in the template to check if this product is in the customer withlist to fill the icon.

  {% if customer is not null and customer.wishlist is not empty %}
    {% for itemId in customer.wishlist %}
      {% if itemId == product.id %}
        {% set in_wishlist = true %}
      {% endif %}
    {% endfor %}
  {% endif %}
Then add this block in the card div or where you would like to show the heart icon.
      <span class="add-to-wishlist" data-wishlist-id="{{ product.id }}">
        {% if customer %}
          <a class="icon-heart-mask {% if in_wishlist == true %}filled{% endif %}" onclick="addToWishlist(this, '{{ product.id }}')"></a>
        {% else %}
          <a class="icon-heart-mask" href="/auth/login?redirect_to={{ requestUri() }}"></a>
        {% endif %}
        <img class="loader d-none" src="{{ asset_url }}spinner.gif" width="20" height="20"/>
      </span>
{% endif %}
Result
Product card component and product page.png

2. For Main.js File:#

Insert the following in the main.js file or the main javascript code file you have:
function fillWishlistItems(items) {
  items.forEach((product) => {
    $(`.add-to-wishlist[data-wishlist-id=${product.id}]`)
      .find(".icon-heart-mask")
      .addClass("filled");
  });
}

function addToWishlist(elm, productId) {
  $(elm).siblings(".add-to-wishlist .loader").removeClass("d-none");
  $(elm).addClass("d-none");

  // Remove From Wishlist if added
  if ($(elm).hasClass("filled")) {
    return removeFromWishlist(elm, productId);
  }

  zid.store.customer.addToWishlist(productId).then((response) => {
    if (response.status === "success") {
      $(elm).siblings(".add-to-wishlist .loader").addClass("d-none");
      $(elm).addClass("filled").removeClass("d-none");

      toastr.success(response.data.message);
    } else {
      toastr.error(response.data.message);
    }
  });
}

function removeFromWishlist(elm, productId) {
  $(elm).siblings(".add-to-wishlist .loader").removeClass("d-none");
  $(elm).addClass("d-none");
  zid.store.customer.removeFromWishlist(productId).then((response) => {
    if (response.status === "success") {
      $(elm).siblings(".add-to-wishlist .loader").addClass("d-none");
      $(elm).removeClass("d-none filled");

      toastr.success(response.data.message);

      if (location.pathname === '/account-wishlist') {
        location.reload();
      }

    } else {
      toastr.error(response.data.message);
    }
  });
}

function shareWishlist() {
  $(".share-wishlist .loader").removeClass("d-none").siblings(".share-icon").addClass("d-none");
  zid.store.customer.shareWishlist().then(async (response) => {
    if (response.status === "success") {
      $(".share-wishlist .loader").addClass("d-none").siblings(".share-icon").removeClass("d-none");

      if (response.data.link) {
        try {
          await navigator.clipboard.writeText(response.data.link);
          toastr.success(response.data.message);
        } catch (error) {
          console.log(error);
        }
      }

    } else {
      toastr.error(response.data.message);
    }
  });
}
You can replace toaster notification with any you’re using.

3. Wishlist page and Shared wishlist:#

You need to create two separate pages for account-wishlist.twig is for listing customer wishlist and wishlist.twig is for listing shared wishlist.
For account-wishlist.twig page, you can add this in the template, for example:
{% extends "layout.twig" %}

{% block header %} {{ include('header.twig') }} {% endblock %}

{% block main_content %}
    <div class="container-parent">
        <div class="container">
            <div class="d-flex">
                <div class="flex-grow-1">
                    <div class="account-content">
                        <div>
                            <div id="wishlist-list" class="row">
                                {% for product in wishlist.data %}
                                    <div class="col-6 col-lg-4 py-3">
                                        {% include 'product-card.twig' with {'product' : product, 'index': key} %}
                                    </div>
                                {% endfor %}
                            </div>
                            {% include 'pagination.twig' with { 'totalPages' : products.last_page , 'currentPage' : products.current_page } %}
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block footer %} {{ include('footer.twig') }} {% endblock %}
You’ll need to add the topbar of the page with a share button to allow customers to share their wishlist with others; you can fire the function of shareWishlist to create a link and copy it to the clipboard.
Share button snippet:
<button class="btn btn-sm btn-outline-secondary share-wishlist m-3" onclick="shareWishlist()">
        <img class="loader d-none" src="{{ asset_url }}spinner.gif" width="25" height="20"/>
        <span class="align-middle share-icon">
          <i class="fa fa-share"></i>
        </span>
        <span class="px-1">{{ locals.shareLabel }}</span>
</button>
Result
Share button snippet.png
For wishlist.twig page (listing shared wishlist):
{% extends "layout.twig" %}

{% block header %} {{ include('header.twig') }} {% endblock %}

{% block top_links %}
    <style>
      .add-to-wishlist, .share-wishlist {
        display: none !important;
      }
    </style>
{% endblock %}


{% block main_content %}
    <div class="container-parent">
        <div class="container">
            <div class="d-flex">
                <div class="flex-grow-1">
                    <div class="account-content">
                        <div>
                            <div id="wishlist-list" class="row">
                                {% for product in wishlist.data %}
                                    <div class="col-6 col-md-4 col-lg-3 py-3">
                                        {% include 'product-card.twig' with {'product' : product, 'index': key} %}
                                    </div>
                                {% endfor %}
                            </div>
                            {% include 'pagination.twig' with { 'totalPages' : products.last_page , 'currentPage' : products.current_page } %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block footer %} {{ include('footer.twig') }} {% endblock %}

{% block script %}
	<script defer>
		$(`.add-to-wishlist .share-wishlist`).remove();
	</script>
{% endblock %}
Should be the same as account-wishlist.twig but without the share button, profile tabs and heart icon.

4. Custom CSS example:#

.add-to-wishlist {
  position: absolute;
  right: 0;
  z-index: 1;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  margin: 10px;
  width: 40px;
  height: 35px;
  cursor: pointer;
  border-radius: 5px;
  background-color: white;
}

.rtl .add-to-wishlist {
  right: unset;
  left: 0;
}

.icon-heart-mask {
  display: inline-block;
  width: 25px;
  height: 20px;
  mask-size: 100%;
  mask-position: center;
  mask-repeat: no-repeat;
  mask-image: url('./heart-outlined.svg');
  background-color: var(--secondary, #A1A0A9);
}

.icon-heart-mask.filled {
  mask-image: url('./heart-filled.svg');
  background-color: var(--primary_color, #D86F6F);
}

5. Display Wishlist in Customer Profile#

To display the customer's wishlist within their profile, you can use the following code snippet. This will retrieve and show the wishlist data dynamically.
This function fetches the relevant wishlist data and integrates it into the customer’s profile page.
Modified at 2025-03-20 11:30:36
Previous
Store's Main Navigation Menu
Next
Products Badges
Built with