I want to know how to create a custom module to disable this welcome message.
2 Answers
Create new module Vendor/Module
or use old/previous module for this. In etc/di.xml
file of your module override EmailNotification
with following code:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Customer\Model\EmailNotification" type="Vendor\Module\Model\Plugin\EmailNotification" />
</config>
Now create file in Vendor/Module/Model/Plugin/EmailNotification.php
<?php
namespace Vendor\Module\Model\Plugin;
class EmailNotification extends \Magento\Customer\Model\EmailNotification
{
public function aroundNewAccount(\Magento\Customer\Model\EmailNotification $subject, \Closure $proceed)
{
return $subject;
}
}
-
2
-
New account creation Email is fire from Magento\Customer\Model\EmailNotification::newAccount
So, if we don't run the code of newAccount method then welcome email is not firing
That you have to create on a Plugin (Interceptors) on method newAccount and stop running all internal code of this original method .
See how to implement plugin at https://devdocs.magento.com/guides/v2.3/extension-dev-guide/plugins.html
- Create a custom module and define plugin at di.xml in
app/code/{Vendor}/{Modulename}/etc/
.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Customer\Model\EmailNotification">
<plugin name="stop_welcome_email" sortOrder="1"
type="{Vendor}\{Modulename}\Plugin\EmailNotificationPlugin" />
</type>
</config>
Plugin class:
<?php
namespace {Vendor}\{Modulename}\Plugin;
class EmailNotification {
public function aroundnewAccount(
\Magento\Customer\Model\EmailNotification $subject,
\Closure $proceed,
\Magento\Customer\Model\CustomerInterface $customer,
$type = self::NEW_ACCOUNT_EMAIL_REGISTERED,
$backUrl = '',
$storeId = 0,
$sendemailStoreId = null
) {
return ;
}
}
-
I created a plugin according to your answer. When I enabled the plugin and registered the account at the front desk, I received a prompt We can't save the customer. But this account can still be seen in the background.– yoyoMar 12, 2019 at 9:47