Commit ba80f46dbd3 for woocommerce

commit ba80f46dbd3f98cbd81dbd18cb2856ae52efbf74
Author: Ján Mikláš <neosinner@gmail.com>
Date:   Mon Jun 22 11:47:04 2026 +0200

    Fix pending cancelled order admin emails (#65855)

    * Fix pending cancelled order admin emails

    * Add changelog entry for pending cancelled emails

    * Update E2E settings test for new cancelled order email description

    The cancelled order email description now includes 'pending' orders;
    update the settings-crud API test assertion to match.

    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

    ---------

    Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/wooplug-6880-pending-cancelled-admin-email b/plugins/woocommerce/changelog/wooplug-6880-pending-cancelled-admin-email
new file mode 100644
index 00000000000..62a9736663a
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-6880-pending-cancelled-admin-email
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Send cancelled order admin emails when pending orders are cancelled.
diff --git a/plugins/woocommerce/includes/class-wc-emails.php b/plugins/woocommerce/includes/class-wc-emails.php
index bcbd3c7a7f6..3ec1c534a11 100644
--- a/plugins/woocommerce/includes/class-wc-emails.php
+++ b/plugins/woocommerce/includes/class-wc-emails.php
@@ -104,6 +104,7 @@ class WC_Emails {
 				'woocommerce_order_status_pending_to_processing',
 				'woocommerce_order_status_pending_to_completed',
 				'woocommerce_order_status_processing_to_cancelled',
+				'woocommerce_order_status_pending_to_cancelled',
 				'woocommerce_order_status_pending_to_failed',
 				'woocommerce_order_status_pending_to_on-hold',
 				'woocommerce_order_status_failed_to_processing',
diff --git a/plugins/woocommerce/includes/emails/class-wc-email-cancelled-order.php b/plugins/woocommerce/includes/emails/class-wc-email-cancelled-order.php
index e9fcf578ffb..c5755e7a8f1 100644
--- a/plugins/woocommerce/includes/emails/class-wc-email-cancelled-order.php
+++ b/plugins/woocommerce/includes/emails/class-wc-email-cancelled-order.php
@@ -43,18 +43,19 @@ if ( ! class_exists( 'WC_Email_Cancelled_Order', false ) ) :
 			// Triggers for this email.
 			add_action( 'woocommerce_order_status_processing_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 );
 			add_action( 'woocommerce_order_status_on-hold_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 );
+			add_action( 'woocommerce_order_status_pending_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 );

 			// Call parent constructor.
 			parent::__construct();

 			// Must be after parent's constructor which sets `email_improvements_enabled` property.
 			$this->description = $this->email_improvements_enabled
-				? __( 'Receive an email notification when an order that was processing or on hold gets cancelled', 'woocommerce' )
-				: __( 'Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously processing or on-hold).', 'woocommerce' );
+				? __( 'Receive an email notification when an order that was pending, processing, or on hold gets cancelled', 'woocommerce' )
+				: __( 'Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously pending, processing, or on-hold).', 'woocommerce' );

 			if ( $this->block_email_editor_enabled ) {
 				$this->title       = __( 'Canceled order', 'woocommerce' );
-				$this->description = __( 'Notifies admins when an order that was processing or on hold has been canceled.', 'woocommerce' );
+				$this->description = __( 'Notifies admins when an order that was pending, processing, or on hold has been canceled.', 'woocommerce' );
 			}

 			// Other settings.
diff --git a/plugins/woocommerce/tests/e2e-pw/tests/api-tests/settings/settings-crud.test.ts b/plugins/woocommerce/tests/e2e-pw/tests/api-tests/settings/settings-crud.test.ts
index 57ab0ab3560..ded0013386f 100644
--- a/plugins/woocommerce/tests/e2e-pw/tests/api-tests/settings/settings-crud.test.ts
+++ b/plugins/woocommerce/tests/e2e-pw/tests/api-tests/settings/settings-crud.test.ts
@@ -166,7 +166,7 @@ test.describe( 'Settings API tests: CRUD', () => {
 						id: 'email_cancelled_order',
 						label: 'Cancelled order',
 						description:
-							'Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously processing or on-hold).',
+							'Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously pending, processing, or on-hold).',
 						parent_id: 'email',
 						sub_groups: expect.arrayContaining( [] ),
 					} ),
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-emails-tests.php b/plugins/woocommerce/tests/php/includes/class-wc-emails-tests.php
index 39bceac5f07..d8e4261b443 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-emails-tests.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-emails-tests.php
@@ -61,6 +61,48 @@ class WC_Emails_Tests extends \WC_Unit_Test_Case {
 		$this->assertSame( $expected, $actual );
 	}

+	/**
+	 * @testdox Pending to cancelled order status changes trigger transactional email notifications.
+	 */
+	public function test_pending_to_cancelled_status_change_triggers_transactional_email_notifications(): void {
+		$hook             = 'woocommerce_order_status_pending_to_cancelled';
+		$captured_actions = array();
+		$email_actions    = function ( $actions ) use ( &$captured_actions, $hook ) {
+			$captured_actions = $actions;
+			return in_array( $hook, $actions, true ) ? array( $hook ) : array();
+		};
+
+		remove_action( $hook, array( 'WC_Emails', 'send_transactional_email' ), 10 );
+		remove_action( $hook, array( 'WC_Emails', 'queue_transactional_email' ), 10 );
+		add_filter( 'woocommerce_email_actions', $email_actions, 999 );
+		add_filter( 'woocommerce_defer_transactional_emails', '__return_false', 999 );
+
+		WC_Emails::init_transactional_emails();
+
+		remove_filter( 'woocommerce_email_actions', $email_actions, 999 );
+		remove_filter( 'woocommerce_defer_transactional_emails', '__return_false', 999 );
+
+		$this->assertContains( $hook, $captured_actions, 'Pending to cancelled status changes should be part of the default transactional email action list.' );
+		$this->assertSame( 10, has_action( $hook, array( 'WC_Emails', 'send_transactional_email' ) ), 'Pending to cancelled status changes should dispatch transactional emails.' );
+
+		remove_action( $hook, array( 'WC_Emails', 'send_transactional_email' ), 10 );
+	}
+
+	/**
+	 * @testdox Admin cancelled order email listens for pending to cancelled notifications.
+	 */
+	public function test_cancelled_order_email_listens_for_pending_to_cancelled_notifications(): void {
+		$email_object    = new WC_Emails();
+		$emails          = $email_object->get_emails();
+		$cancelled_email = $emails['WC_Email_Cancelled_Order'];
+
+		$this->assertSame(
+			10,
+			has_action( 'woocommerce_order_status_pending_to_cancelled_notification', array( $cancelled_email, 'trigger' ) ),
+			'Cancelled order emails should notify admins when a pending order is cancelled.'
+		);
+	}
+
 	/**
 	 * Test that order meta function outputs linked meta.
 	 */