1
use Magento\Quote\Model\QuoteManagement;
...

// Create order from quote

$order = $this->quoteManagement->submit($quote);

// This code send mail automatically

//also used **$order->setCanSendNewEmailFlag(false);** 

// But this not working in magento 2.3.0
1

Overwrite/pluginize following class which is responsible for sending order mail.

vendor/magento/module-quote/Observer/SubmitObserver.php

You can try the following using plugin:

app/code/SR/MagentoCommunity/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">
    <type name="Magento\Quote\Observer\SubmitObserver">
        <plugin name="SR_MagentoCommunity::stop_sending_order_email_for_custom_payment"
                type="SR\MagentoCommunity\Plugin\Quote\Observer\SubmitObserver" sortOrder="1"/>
    </type>
</config>

app/code/SR/MagentoCommunity/Plugin/Quote/Observer/SubmitObserver.php

<?php
namespace SR\MagentoCommunity\Plugin\Quote\Observer;

class SubmitObserver
{
    public function beforeExecute(
        \Magento\Quote\Observer\SubmitObserver $subject,
        \Magento\Framework\Event\Observer $observer
    ) {
        /** @var  \Magento\Sales\Model\Order $order */
        $order = $observer->getEvent()->getOrder();

        // Add your custom logic here
        $order->setCanSendNewEmailFlag(false);
        return [$observer];
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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