• Home
  • Magento
    • Magento 2
  • Adobe | Magento Cloud
  • Hyva
  • Linux
  • About Me
  • Contact Us

Rohan Hapani

Magento Tutorial | PHP Tutorial | Android Tutorial

Magento, Magento 2

How to Check if Customer Account is Confirmed or not in Magento 2

May 2, 2021
How to Check if Customer Account is Confirmed or not in Magento 2

In this tutorial, Today I will explain to you how to check if customer account is confirmed or not in Magento 2. Sometimes, you need to check programmatically that customer account is confirmed or not. For that you need to inject \Magento\Customer\Api\AccountManagementInterface this class.

You may also like this :

  • How to add new customer address by REST API in Magento 2
  • Magento 2 : Get Default Billing and Shipping Address by Customer ID

Let’s assume that you have created simple module. After that, You can add this below code in app/code/RH/Helloworld/Block/Helloworld.php block file and paste the below code :

Copy Code Copied Use a different Browser

<?php
/**
 * Created By : Rohan Hapani
 */
namespace RH\Helloworld\Block;

class Helloworld extends \Magento\Framework\View\Element\Template
{
    /**
     * @var \Magento\Customer\Api\AccountManagementInterface
     */
    protected $accountManagement;

    /**
     * @param \Magento\Framework\View\Element\Template\Context $context
     * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Customer\Api\AccountManagementInterface $accountManagement,
        array $data = []
    ) {
        $this->accountManagement = $accountManagement;
        parent::__construct($context, $data);
    }

    /**
     * Check account confired or not
     *    
     * @param int $customerId
     * @return string
     */
    public function checkAccountConfired($customerId)
    {
        return $this->accountManagement->getConfirmationStatus($customerId);
    }
}

Now, you can use checkAccountConfired($customerId) function in your template file or any other file. You need to pass customer id when use this function.

You can use this above code in any other files also based on your requirements.

In last, You will receive output like :

  • account_confirmation_required
  • account_confirmed
  • account_confirmation_not_required

That’s it !!!

I hope this blog is easy to understand about how to check if customer account is confirmed or not in Magento 2. In case, I missed anything or need to add some information, always feel free to leave a comment in this blog, I’ll get back with proper solution.

Stay Safe and Stay Connected !!

Post Views: 3,089
Tagged customer, customer-account, magento2

Related Posts

How to Add Custom Global Variable in Hyva Theme Magento 2

January 6, 2025
How to Create Custom Product Slider in Hyva Theme Magento 2

How to Create Custom Product Slider in Hyva Theme Magento 2

November 23, 2024
Magento 2 Luma Theme Fallback in Hyvä theme

Magento 2 : Luma Theme Fallback in Hyvä theme

November 12, 2024

Post navigation

List of Useful Git Commands
Magento 2.3 PWA Installation Guide

Certification Directory

Magento-Certifications

Magento Stack Exchange

profile for Rohan Hapani at Magento Stack Exchange, Q&A for users of the Magento e-Commerce platform

Recent Posts

  • How to Add Custom Global Variable in Hyva Theme Magento 2
  • How to Create Custom Product Slider in Hyva Theme Magento 2
  • Magento 2 : Luma Theme Fallback in Hyvä theme
  • How to Create a Custom Child Theme in Hyva Magento 2
  • How to Install Hyva Theme in Magento 2?

Most Viewed Posts

  • Magento 2 : How to Add Product Grid in UI Form using UIComponent
  • Magento 2 : Create admin grid and form without ui component
  • Magento 2 : Create UI Component Grid and Form
  • Magento 2 : Get Product Collection
  • How to Add Slick Slider in Magento 2

Categories

  • Adobe | Magento Cloud (5)
  • Android (1)
  • Hyva (5)
  • Linux (4)
  • Magento (189)
  • Magento 2 (194)

Recent Posts

  • How to Add Custom Global Variable in Hyva Theme Magento 2
  • How to Create Custom Product Slider in Hyva Theme Magento 2
  • Magento 2 : Luma Theme Fallback in Hyvä theme
  • How to Create a Custom Child Theme in Hyva Magento 2
  • How to Install Hyva Theme in Magento 2?

Categories

  • Adobe | Magento Cloud
  • Android
  • Hyva
  • Linux
  • Magento
  • Magento 2

Archives

  • January 2025
  • November 2024
  • May 2024
  • March 2024
  • February 2024
  • November 2023
  • October 2023
  • August 2023
  • June 2023
  • April 2023
  • October 2022
  • September 2022
  • August 2022
  • June 2022
  • April 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • December 2018
  • November 2018
  • Facebook
  • Twitter
  • LinkedIn
  • YouTube
Copyright © All rights reserved.
Blog Way by ProDesigns
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT