Commit 218c79981 for woocommerce

commit 218c79981183d7cf98cf5ccbf4797f2dc677e3e1
Author: roykho <roykho77@gmail.com>
Date:   Wed Jan 13 14:13:57 2021 -0800

    Prevent duplicate new order email from being sent when changing order status closes #27791

diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php b/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php
index 6e68d6417..27a00dfe1 100644
--- a/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php
+++ b/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php
@@ -118,7 +118,7 @@ class WC_Meta_Box_Order_Actions {

 				WC()->payment_gateways();
 				WC()->shipping();
-				WC()->mailer()->emails['WC_Email_New_Order']->trigger( $order->get_id(), $order );
+				WC()->mailer()->emails['WC_Email_New_Order']->trigger( $order->get_id(), $order, true );

 				do_action( 'woocommerce_after_resend_order_email', $order, 'new_order' );

diff --git a/includes/emails/class-wc-email-new-order.php b/includes/emails/class-wc-email-new-order.php
index 0c063d61e..0b50d5637 100644
--- a/includes/emails/class-wc-email-new-order.php
+++ b/includes/emails/class-wc-email-new-order.php
@@ -80,8 +80,9 @@ if ( ! class_exists( 'WC_Email_New_Order' ) ) :
 		 *
 		 * @param int            $order_id The order ID.
 		 * @param WC_Order|false $order Order object.
+		 * @param bool           $force_send Whether to force send the email.
 		 */
-		public function trigger( $order_id, $order = false ) {
+		public function trigger( $order_id, $order = false, $force_send = false ) {
 			$this->setup_locale();

 			if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
@@ -92,10 +93,19 @@ if ( ! class_exists( 'WC_Email_New_Order' ) ) :
 				$this->object                         = $order;
 				$this->placeholders['{order_date}']   = wc_format_datetime( $this->object->get_date_created() );
 				$this->placeholders['{order_number}'] = $this->object->get_order_number();
+
+				$email_already_sent = $order->get_meta( '_new_order_email_sent' );
+			}
+
+			if ( 'true' === $email_already_sent && ! $force_send ) {
+				return;
 			}

 			if ( $this->is_enabled() && $this->get_recipient() ) {
 				$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
+
+				$order->update_meta_data( '_new_order_email_sent', 'true' );
+				$order->save();
 			}

 			$this->restore_locale();