Skip to main content
Tweeted twitter.com/StackMagento/status/887042914043346944
edited tags
Link
Khoa TruongDinh
  • 32.3k
  • 11
  • 90
  • 156
Source Link
David Fiaty
  • 198
  • 2
  • 14

Magento 2 - Place an order without sending email

I'm using the following code to place an order programmatically in Magento 2:

    // Configure the quote
    $quote = $this->cart->getQuote();
    $quote->setInventoryProcessed(false);
    $quote->setPaymentMethod('custom_gateway');
    $quote->save();

    // Set the payment method
    $payment = $quote->getPayment();
    $payment->importData(['method' => 'custom_gateway']);

    // Update the quote
    $quote->collectTotals()->save();

    // Place the order
    $this->cartManagement->placeOrder($quote->getId());

This code is creating the order as expected, but is also sending an email to the shopper.

I would like to send the confirmation email at a later stage in the process, only when the payment has been confirmed.

How can I place an order without notifying the customer?