0

This question already has an answer here:

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

marked as duplicate by Dhiren Vasoya, Amit Bera magento2 Mar 12 at 9:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

New account creation mail 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 ;     
    }
}
  • 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 at 9:47
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
    di.xml is wrong.Please check – Amit Bera Mar 12 at 8:25
  • @AmitBera updated my answer – Shoaib Munir Mar 12 at 9:07

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