0

I want to know how to create a custom module to disable this welcome message.

2
  • @Shoaib Munir I don't understand where to create the di.xml file and how to create the plugin.
    – yoyo
    Mar 12, 2019 at 8:16
  • Let me tell you in answer Mar 12, 2019 at 8:17

2 Answers 2

0

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
  • 2
    di.xml is wrong.Please check
    – Amit Bera
    Mar 12, 2019 at 8:25
  • @AmitBera updated my answer Mar 12, 2019 at 9:07
0

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

  1. 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 ;     
    }
}
1
  • 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.
    – yoyo
    Mar 12, 2019 at 9:47

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