2

In backend configuration we can enable email confirmation, so customer need to confirm their email first then he can access their account,How to check if customer already confirmed their account programmatically using customer e-mail?

example:

$customer->getByEmail($email);
$customer->isCustomerAlredyConfirmed();
1

You can use this code

/**
 * @var \Magento\Customer\Api\AccountManagementInterface
 */
protected $accountManagement;

public function __construct(
    \Magento\Customer\Api\AccountManagementInterface $accountManagement 
){
    $this->accountManagement = $accountManagement;
}

use this code to know the status

$customer_id = 18;
echo $this->accountManagement->getConfirmationStatus($customer_id);

the result will be one of below options

  • account_confirmation_required

  • account_confirmed

  • account_confirmation_not_required

please look at this file

Magento\Customer\Model\AccountManagement

you can test it quickly by this code

$objectManager =   \Magento\Framework\App\ObjectManager::getInstance();
$customer_id = 18;
$accountManagement = $objectManager->get('\Magento\Customer\Api\AccountManagementInterface');
echo $accountManagement->getConfirmationStatus($customer_id);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.