Magento 2 – How to Stop Standard Order Email

magento2order-email

I am developing a solution with an external payment gateway. I create the order and then send the user to the gateway. When coming back from the gateway with a success i resend the order confirmation in my custom callback controller.

But the order confirmation email is sent once already when the order is first created. How do i intervene and stop this? I does not seem to find the correct event to do this in using an observer.

Best Answer

I think a better approach would be to add any additional functionality that your are trying to achieve to magento order email. By creating your own order email will limit functionality such as "resend order email".

But if you want continue take a look at send(Order $order, $forceSyncMode = false) in magento2/app/code/Magento/Sales/Model/Order/Email/Sender/OrderSender.php

In your custom module create etc/di.xml

<?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\Sales\Model\Order\Email\Sender\OrderSender" type="Company\ModuleName\Model\Order\Email\Sender\OrderSender"/>
</config>