I need to modify the welcome email sent to user upon new account creation. I need to do this in my custom module. I tried to override the function sendNewAccountEmail in Magento\Customer\Model\Customer using preference method and also using plugin method. Both were not working.
For preference method I added the following
In Vendor/Module/etc/di.xml
<preference for="Magento\Customer\Model\Customer" type = "Vendor\Module\Model\Customer" />
Added Customer.php file in the location Vendor\Module\Model\Customer and added the following code
public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
{
echo "It's Working";exit;
$types = $this->getTemplateTypes();
if (!isset($types[$type])) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Please correct the transactional account email type.')
);
}
if (!$storeId) {
$storeId = $this->_getWebsiteStoreId($this->getSendemailStoreId());
}
$this->_sendEmailTemplate(
$types[$type],
'customname/email/account_email_template',
['customer' => $this, 'back_url' => $backUrl, 'store' => $this->getStore()],
$storeId
);
return $this;
}
Still it's not taking the Customer.php file in the module.
echo "It's Working"; is not displaying.
What is the correct method to follow? I tried the plugin method also. It's also not working.