3

I set the configuration for Magento 2 customer to do email confirmation after register and change e-mail, is there a way to confirm customer e-mail programmatically only by customer id or customer e-mail?

$customerId = '35';
$customerEmail = '[email protected]';
$this->confirmCustomerEmailByCustomerId($customerId);  //how ?
$this->confirmCustomerEmailByCustomerEmail($customerEmail); //how ?

2 Answers 2

2

You can confirm the customer registration as following

<?php 

private $customer;

public function __construct(
    ...
    \Magento\Customer\Model\Customer $customer,
    ...
) {
    ...
    $this->customer = $customer;
    ...
}


...

$customerId = '1';
$customer = $this->customer->load($customerId);
$customer->setConfirmation(null);
$customer->save();
1
  • Need to add $customer->sendNewAccountEmail(); after save then its working for me on Magento 2.4.1 Dec 6, 2020 at 7:18
1

When I created accounts, they were already confirmed, but they were disabled! This fixed it:

  $customer = $this->customer->load($customerId);
  $customer->setConfirmation(null);
  $customer->setStatus(1);
  $customer->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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