cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop email on new user register from admin

How to stop email on new user register from admin

Hi Team,

 

We are developing an extension and as extension flow we need required to stop send email if super user create a user from admin section.

 

my steps are

  1. Login to super user (admin section).
  2. Go to Customer section and hit New Customer for create a customer.
  3. Fill all required field and hit save button.
  4. After that a customer created success and a verification email OR password email sent to new create customer's email address.

We need to stop this email from my extension OR any other way.

 

In Magento2 have any way to do this?

 

Thanks

5 REPLIES 5

Re: How to stop email on new user register from admin

For example, you can set the skip_confirmation_if_email registry key.

How is the confirmation email sent on a customer registration? https://mage2.pro/t/1164

Re: How to stop email on new user register from admin

Thanks Dmitry_Fedyuk

 

We check out your solution as you have specified to disable required email verification. but I want to stop complete email sending process in admin create user like "welcome email".

 

As well as do it from my extension end not direct edit in code.

 

did magento2 have any event / Hook for do this process.

Re: How to stop email on new user register from admin

Hi there, in order to stop sending the "welcome" email for an order created through the backend, you should do this:

Create a new module (or existing) and overwrite the create order model:

 

<?xml version="1.0"?>
<config>
    <modules>
        <Module_Adminhtml>
            <version>0.1.0</version>
        </Module_Adminhtml>
    </modules>
    <global>
        <models>
            <adminhtml>
                <rewrite>
                    <sales_order_create>Module_Adminhtml_Model_Sales_Order_Create</sales_order_create>
                </rewrite>
            </adminhtml>
        </models>
    </global>
</config>

And then, overwrite the createOrderMethod:

 

<?php
/**
 * Created by PhpStorm.
 * User: roberto
 * Date: 20/11/16
 * Time: 05:54 PM
 */
class Module_Adminhtml_Model_Sales_Order_Create extends Mage_Adminhtml_Model_Sales_Order_Create
{
    /**
     * Create new order
     *
     * @return Mage_Sales_Model_Order
     */
    public function createOrder()
    {
        $this->_prepareCustomer();
        $this->_validate();
        $quote = $this->getQuote();
        $this->_prepareQuoteItems();

        $service = Mage::getModel('sales/service_quote', $quote);
        /** @var Mage_Sales_Model_Order $oldOrder */
        $oldOrder = $this->getSession()->getOrder();
        if ($oldOrder->getId()) {
            $originalId = $oldOrder->getOriginalIncrementId();
            if (!$originalId) {
                $originalId = $oldOrder->getIncrementId();
            }
            $orderData = array(
                'original_increment_id'     => $originalId,
                'relation_parent_id'        => $oldOrder->getId(),
                'relation_parent_real_id'   => $oldOrder->getIncrementId(),
                'edit_increment'            => $oldOrder->getEditIncrement()+1,
                'increment_id'              => $originalId.'-'.($oldOrder->getEditIncrement()+1)
            );
            $quote->setReservedOrderId($orderData['increment_id']);
            $service->setOrderData($orderData);

            $oldOrder->cancel();
        }

        /** @var Mage_Sales_Model_Order $order */
        $order = $service->submit();
        $customer = $quote->getCustomer();
        if ((!$customer->getId() || !$customer->isInStore($this->getSession()->getStore()))
            && !$quote->getCustomerIsGuest()
        ) {
            $customer->setCreatedAt($order->getCreatedAt());
            $customer->save();
                //->sendNewAccountEmail('registered', '', $quote->getStoreId());;
        }
        if ($oldOrder->getId()) {
            $oldOrder->setRelationChildId($order->getId());
            $oldOrder->setRelationChildRealId($order->getIncrementId());
            $oldOrder->save();
            $order->save();
        }
        if ($this->getSendConfirmation()) {
            $order->queueNewOrderEmail();
        }

        Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $quote));

        return $order;
    }
}

Notice before the customer->save(); there is the code for send the welcome email, just comment this line :

 //->sendNewAccountEmail('registered', '', $quote->getStoreId());;

Greetings.

Re: How to stop email on new user register from admin

 My solution was, if one installed Magento2 on Linux and uses postfix, one could configure postfix to discard the emails contain e.g. "Owner" in "From" field or contain "Welcome to" in "Subject" field.

 

See: http://mattshaw.org/news/how-to-filter-mail-with-postfix-header_checks/ 

Re: How to stop email on new user register from admin

You can use this extension for disabling email notifications in Magento 2.