{"id":1698,"date":"2021-04-15T12:23:46","date_gmt":"2021-04-15T12:23:46","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/programmatically-check-if-customer-account-is-confirmed-or-not-in-magento-2\/"},"modified":"2025-07-16T18:12:30","modified_gmt":"2025-07-16T12:42:30","slug":"programmatically-check-if-customer-account-is-confirmed-or-not-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/programmatically-check-if-customer-account-is-confirmed-or-not-in-magento-2\/","title":{"rendered":"How to Programmatically Check if Customer Account is Confirmed or not in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 store owners tend to collect customers\u2019 data for various purposes such as marketing, understanding customers\u2019 behaviour and shopping pattern, or simply offer a better user experience.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apart from collecting customers\u2019 data is to collect their Email ID while registering with\u00a0Magento 2\u00a0store. Every store owner usually confirms if the given Email ID is correct or not.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, when you programmatically login customer without a password, in that case even if the email is not confirmed, the customer can log in. In this situation, you need to&nbsp;<em><strong>programmatically check if customer account is confirmed or not in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The below code is the method for the same:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to&nbsp;Programmatically Check if Customer Account is Confirmed or not in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below code in the helper file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace [Vendor]\\[Module]\\Helper;\n\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\nuse Magento\\Framework\\App\\Helper\\Context;\n\nclass Data extends AbstractHelper\n{\n    protected $accountManagement;\n\n    public function __construct(\n        Context $context,\n        \\Magento\\Customer\\Api\\AccountManagementInterface $accountManagement\n    )\n    {\n        $this->accountManagement = $accountManagement;\n        parent::__construct($context);\n    }\n\n    public function isAccountConfirmed($customerId)\n    {\n        return $this->accountManagement->getConfirmationStatus($customerId);\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>isAccountConfirmed()<\/strong>&nbsp;function returns result as :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>account_confirmation_required<\/li>\n\n\n\n<li>account_confirmed<\/li>\n\n\n\n<li>account_confirmation_not_required<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s all!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the above solution and stop the unauthenticated user in your store or else, you could just use the&nbsp;<a href=\"https:\/\/meetanshi.com\/magento-2-restrict-fake-registration.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Restrict Fake Registration<\/a>&nbsp;extension!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, please share the tutorial with the Magento community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 store owners tend to collect customers\u2019 data for various purposes such as marketing, understanding customers\u2019 behaviour and shopping pattern, or simply offer a&#8230;<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1698","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1698"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1698\/revisions"}],"predecessor-version":[{"id":18127,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1698\/revisions\/18127"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}