How To

How to Get Wishlist Data Using Customer ID in Magento 2

Hello Magento Friends,

The current Magento tutorial blog illustrates How to Get Wishlist Data Using Customer ID in Magento 2.

Wishlist is a useful tool to help customers save their favorite items for future purchases. Learn How to Configure Wishlist in Magento 2.

The customer’s wishlist items are linked using the customer ID. To retrieve a customer’s wishlist items, you need the customer ID to filter the wishlist collection by the corresponding customer. The customer ID serves as a unique identifier to fetch the wishlist items associated with that specific customer.

Using the below step, you can get wishlist data, including product ID and quantity of product from customer ID in Magento 2.

Steps to Get Wishlist Data Using Customer ID in Magento 2:

Step 1: Create Data.php on the given path.

{{magento_root}}/app/code/Vendor/Extension/Helper/Data.php

Then add the code as follows.

<?php
namespace Vendor\Extension\Helper;
use Magento\Framework\App\Helper\Context;
use Magento\Wishlist\Model\Wishlist;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    protected $wishlist;
    public function __construct(
        Wishlist $wishlist,
        Context $context
    ) {
        parent::__construct($context);
        $this->wishlist = $wishlist;
    }
    public function getwishlistdata($customerId)
    {
        return $this->wishlist->loadByCustomerId($customerId)->getItemCollection()->getData();
    }

}

You can use this method in the controller file or block file as per your requirement.

Conclusion:

Hence, using the above method, you can easily get wishlist data of customers using the customer ID in Magento 2. If you face any errors while implementing the above code, kindly share them with me through the comment section.

Share the article through social media platforms and with your other Magento friends. Stay in touch with us for more.

Happy Coding!

Click to rate this post!
[Total: 1 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

How to Get Database Value in Shopify Theme App Extension using App Proxy?

In this article, we will learn about how to get database value in the Shopify…

1 day ago

Mastering Tailwind CSS in Laravel: A Comprehensive Guide

Tailwind CSS has emerged as a powerful utility-first CSS framework, offering developers a unique approach…

3 days ago

React Native or Flutter in 2024

The mobile app development field has witnessed a rapid revolution over the past few years.…

5 days ago

Magento 2: How To Call JS on the Checkout Page?

Hello Magento mates, Today we will learn to add a call JS on the checkout…

1 week ago

Boost Your SEM Game: Unveiling the Top 10 Tools for Marketers in 2024

Business survival in today’s digital world has become extremely difficult. Using traditional marketing techniques is…

1 week ago

Five Essential Payroll Compliance Tips for eCommerce Startups

Are you setting up a payroll system for your eCommerce startup? Ensuring compliance with myriad…

1 week ago