Commit 5bbb2e82216 for woocommerce
commit 5bbb2e822169951023f1a4542dee7e00c63d31cb
Author: iris-woocommerce[bot] <282076412+iris-woocommerce[bot]@users.noreply.github.com>
Date: Wed Nov 25 10:10:12 2026 -0800
Abilities: let extensions add their order emails to order-send-email (#71395)
* Abilities: let extensions add their order emails to order-send-email
Co-authored-by: matticbot <matticbot@users.noreply.github.com>
* Point to the logs when an order email trigger throws
The send-failed error told the agent to check the mail setup, which is the
wrong fix when the trigger callback threw before any mail was sent.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* Require a billing email only for customer order emails
An extension can register a store email, such as a packing list for the
warehouse. That email goes to the recipients in the email settings, so
order-send-email no longer refuses it when the order has no billing email.
The ability description now covers store emails too.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: zaguiini <luis.felipe.zaguini@automattic.com>
Co-authored-by: matticbot <matticbot@users.noreply.github.com>
Co-authored-by: Luis Felipe Zaguini <luisfelipezaguini@gmail.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
diff --git a/plugins/woocommerce/changelog/add-order-send-email-extension-emails b/plugins/woocommerce/changelog/add-order-send-email-extension-emails
new file mode 100644
index 00000000000..669f28201fa
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-order-send-email-extension-emails
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Extensible abilities: let extensions add order emails to order-send-email, behind an experimental flag.
+
diff --git a/plugins/woocommerce/src/Abilities/ExtensibleAbilities.php b/plugins/woocommerce/src/Abilities/ExtensibleAbilities.php
index 8ea110c39d1..95aa3eb6755 100644
--- a/plugins/woocommerce/src/Abilities/ExtensibleAbilities.php
+++ b/plugins/woocommerce/src/Abilities/ExtensibleAbilities.php
@@ -9,6 +9,7 @@ namespace Automattic\WooCommerce\Abilities;
use Automattic\WooCommerce\Internal\Utilities\StagedMethod;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
+use Automattic\WooCommerce\Utilities\OrderUtil;
defined( 'ABSPATH' ) || exit;
@@ -25,6 +26,7 @@ defined( 'ABSPATH' ) || exit;
* the object one time.
* An extension also registers a query filter, which the list ability of the
* resource accepts under `filters.extensions.<namespace>.<filter>`.
+ * And it registers an order email that the order-send-email ability can send.
*
* The API is experimental while the `extensible_abilities` feature exists.
*
@@ -69,6 +71,13 @@ class ExtensibleAbilities {
*/
private static array $primes = array();
+ /**
+ * Order emails that the order-send-email ability can send, keyed by email name.
+ *
+ * @var array<string, array{email_class: string, description: string, statuses: array<int, string>, trigger_callback: callable|null}>
+ */
+ private static array $order_emails = array();
+
/**
* Whether the store enabled the experimental feature.
*
@@ -804,6 +813,85 @@ class ExtensibleAbilities {
}
}
+ /**
+ * Register an order email that the `woocommerce/order-send-email` ability can send.
+ *
+ * Call it inside the `woocommerce_extensible_abilities_init` action. The ability accepts the email
+ * as `<namespace>:<email>` only when the `extensible_abilities` feature is on. It lists the email
+ * with its description and statuses in its input schema, so an agent can choose it.
+ *
+ * @since 11.5.0
+ *
+ * @param array $args {
+ * Order email arguments.
+ *
+ * @type string $namespace Slug of the extension that owns the email, such as `deposits`.
+ * @type string $email Slug of the email inside the namespace, such as `payment-reminder`.
+ * @type string $email_class Key of the email in WC()->mailer()->get_emails(), usually its class name.
+ * @type string $description One sentence on what the email says and who gets it, for agents.
+ * @type string[] $statuses Optional. Order statuses in which the email can be sent, without the
+ * `wc-` prefix. The ability refuses the email for an order with another
+ * status. Leave it out when the email can be sent in any status.
+ * @type callable $trigger_callback Optional. Receives the WC_Email and the order, and sends the email.
+ * Leave it out when `$email->trigger( $order_id, $order )` sends it.
+ * The ability checks that the email was sent through the
+ * `woocommerce_email_sent` action of that WC_Email.
+ * }
+ */
+ public static function register_order_email( array $args ): void {
+ if ( did_action( 'woocommerce_extensible_abilities_init' ) && ! doing_action( 'woocommerce_extensible_abilities_init' ) ) {
+ wc_doing_it_wrong( __METHOD__, 'Register an order email inside the woocommerce_extensible_abilities_init action, before the abilities build their schemas.', '11.5.0' );
+ return;
+ }
+ foreach ( array( 'namespace', 'email' ) as $key ) {
+ if ( ! is_string( $args[ $key ] ?? null ) || '' === $args[ $key ] || sanitize_key( $args[ $key ] ) !== $args[ $key ] ) {
+ wc_doing_it_wrong( __METHOD__, sprintf( 'The "%s" argument must be a slug of lowercase letters, numbers, dashes and underscores.', $key ), '11.5.0' );
+ return;
+ }
+ }
+ foreach ( array( 'email_class', 'description' ) as $key ) {
+ if ( ! is_string( $args[ $key ] ?? null ) || '' === trim( $args[ $key ] ) ) {
+ wc_doing_it_wrong( __METHOD__, sprintf( 'The "%s" argument must be a non-empty string.', $key ), '11.5.0' );
+ return;
+ }
+ }
+ $statuses = $args['statuses'] ?? array();
+ if ( ! is_array( $statuses ) || count( array_filter( $statuses, 'is_string' ) ) !== count( $statuses ) ) {
+ wc_doing_it_wrong( __METHOD__, 'The "statuses" argument must be a list of order statuses.', '11.5.0' );
+ return;
+ }
+ if ( isset( $args['trigger_callback'] ) && ! is_callable( $args['trigger_callback'] ) ) {
+ wc_doing_it_wrong( __METHOD__, 'The "trigger_callback" argument must be callable.', '11.5.0' );
+ return;
+ }
+
+ $name = $args['namespace'] . ':' . $args['email'];
+ if ( isset( self::$order_emails[ $name ] ) ) {
+ wc_doing_it_wrong( __METHOD__, sprintf( 'The order email "%s" is already registered.', $name ), '11.5.0' );
+ return;
+ }
+
+ self::$order_emails[ $name ] = array(
+ 'email_class' => $args['email_class'],
+ 'description' => $args['description'],
+ 'statuses' => array_values( array_unique( array_map( array( OrderUtil::class, 'remove_status_prefix' ), $statuses ) ) ),
+ 'trigger_callback' => $args['trigger_callback'] ?? null,
+ );
+ }
+
+ /**
+ * Order emails that extensions registered, keyed by `<namespace>:<email>`. Empty when the feature is off.
+ *
+ * @internal
+ *
+ * @since 11.5.0
+ *
+ * @return array<string, array{email_class: string, description: string, statuses: array<int, string>, trigger_callback: callable|null}>
+ */
+ public static function get_order_emails(): array {
+ return self::is_enabled() ? self::$order_emails : array();
+ }
+
/**
* Log an error from an extension callback. A logger that throws does not
* stop the ability.
diff --git a/plugins/woocommerce/src/Internal/Abilities/Domain/OrderSendEmail.php b/plugins/woocommerce/src/Internal/Abilities/Domain/OrderSendEmail.php
index 6e8ddbadda3..4c6bed3c078 100644
--- a/plugins/woocommerce/src/Internal/Abilities/Domain/OrderSendEmail.php
+++ b/plugins/woocommerce/src/Internal/Abilities/Domain/OrderSendEmail.php
@@ -8,6 +8,7 @@ declare( strict_types=1 );
namespace Automattic\WooCommerce\Internal\Abilities\Domain;
use Automattic\WooCommerce\Abilities\AbilityDefinition;
+use Automattic\WooCommerce\Abilities\ExtensibleAbilities;
use Automattic\WooCommerce\Enums\OrderStatus;
use Automattic\WooCommerce\Internal\Abilities\Domain\Traits\OrderAbilityTrait;
@@ -21,21 +22,32 @@ class OrderSendEmail extends AbstractDomainAbility implements AbilityDefinition
use OrderAbilityTrait;
/**
- * Email class for each email that the ability can send.
+ * Get the emails that the ability can send: Core's emails, then the order
+ * emails that extensions register with ExtensibleAbilities::register_order_email().
+ *
+ * @return array<string, array{email_class: string, description: string, statuses: array<int, string>, trigger_callback?: callable|null}>
*/
- private const EMAIL_CLASSES = array(
- 'invoice' => 'WC_Email_Customer_Invoice',
- 'processing' => 'WC_Email_Customer_Processing_Order',
- 'completed' => 'WC_Email_Customer_Completed_Order',
- );
+ private static function get_emails(): array {
+ $core_emails = array(
+ 'invoice' => array(
+ 'email_class' => 'WC_Email_Customer_Invoice',
+ 'description' => __( 'The order details, with a payment link while the order is pending.', 'woocommerce' ),
+ 'statuses' => array(),
+ ),
+ 'processing' => array(
+ 'email_class' => 'WC_Email_Customer_Processing_Order',
+ 'description' => __( 'Tells the customer that the order is being processed.', 'woocommerce' ),
+ 'statuses' => array( OrderStatus::PROCESSING ),
+ ),
+ 'completed' => array(
+ 'email_class' => 'WC_Email_Customer_Completed_Order',
+ 'description' => __( 'Tells the customer that the order is complete.', 'woocommerce' ),
+ 'statuses' => array( OrderStatus::COMPLETED ),
+ ),
+ );
- /**
- * Order status that each status email needs.
- */
- private const REQUIRED_STATUSES = array(
- 'processing' => OrderStatus::PROCESSING,
- 'completed' => OrderStatus::COMPLETED,
- );
+ return array_merge( $core_emails, ExtensibleAbilities::get_order_emails() );
+ }
/**
* Get the ability name.
@@ -59,7 +71,7 @@ class OrderSendEmail extends AbstractDomainAbility implements AbilityDefinition
return array(
'label' => __( 'Send order email', 'woocommerce' ),
'description' => __(
- 'Send an order email to the customer again.',
+ 'Send an order email again. A customer email goes to the billing email of the order, and a store email goes to the recipients set in the email settings.',
'woocommerce'
),
'category' => 'woocommerce',
@@ -98,29 +110,17 @@ class OrderSendEmail extends AbstractDomainAbility implements AbilityDefinition
}
$email_name = $input['email'];
- $refusal = self::get_status_refusal( $order, $email_name );
+ $email_args = self::get_emails()[ $email_name ];
+ $refusal = self::get_status_refusal( $order, $email_name, $email_args['statuses'] );
if ( is_wp_error( $refusal ) ) {
return $refusal;
}
- if ( ! is_email( $order->get_billing_email() ) ) {
- return new \WP_Error(
- 'woocommerce_ability_order_email_no_recipient',
- __( 'The order has no valid billing email. Set billing.email with the woocommerce/order-update ability, then send the email again.', 'woocommerce' ),
- array( 'status' => 400 )
- );
- }
-
WC()->payment_gateways();
WC()->shipping();
- /**
- * The email to send, or null when a filter removed its class.
- *
- * @var \WC_Email_Customer_Invoice|\WC_Email_Customer_Processing_Order|\WC_Email_Customer_Completed_Order|null $email
- */
- $email = WC()->mailer()->get_emails()[ self::EMAIL_CLASSES[ $email_name ] ] ?? null;
+ $email = WC()->mailer()->get_emails()[ $email_args['email_class'] ] ?? null;
if ( ! $email instanceof \WC_Email || ( ! $email->is_manual() && ! $email->is_enabled() ) ) {
return new \WP_Error(
@@ -131,6 +131,14 @@ class OrderSendEmail extends AbstractDomainAbility implements AbilityDefinition
);
}
+ if ( $email->is_customer_email() && ! is_email( $order->get_billing_email() ) ) {
+ return new \WP_Error(
+ 'woocommerce_ability_order_email_no_recipient',
+ __( 'The order has no valid billing email. Set billing.email with the woocommerce/order-update ability, then send the email again.', 'woocommerce' ),
+ array( 'status' => 400 )
+ );
+ }
+
$sent = false;
$capture = static function ( $result, $email_id ) use ( &$sent, $email ): void {
if ( $email_id === $email->id ) {
@@ -142,9 +150,29 @@ class OrderSendEmail extends AbstractDomainAbility implements AbilityDefinition
/** This action is documented in includes/admin/meta-boxes/class-wc-meta-box-order-actions.php */
do_action( 'woocommerce_before_resend_order_emails', $order, $email->id );
+ $failed = false;
add_action( 'woocommerce_email_sent', $capture, 10, 2 );
- $email->trigger( $order->get_id(), $order );
- remove_action( 'woocommerce_email_sent', $capture, 10 );
+ try {
+ if ( isset( $email_args['trigger_callback'] ) ) {
+ call_user_func( $email_args['trigger_callback'], $email, $order );
+ } elseif ( method_exists( $email, 'trigger' ) ) {
+ $email->trigger( $order->get_id(), $order );
+ }
+ } catch ( \Throwable $e ) {
+ $failed = true;
+ wc_get_logger()->error( sprintf( 'Sending the %1$s email of order %2$d failed: %3$s', $email_name, $order->get_id(), $e->getMessage() ), array( 'source' => 'extensible-abilities' ) );
+ } finally {
+ remove_action( 'woocommerce_email_sent', $capture, 10 );
+ }
+
+ if ( ! $sent && $failed ) {
+ return new \WP_Error(
+ 'woocommerce_ability_order_email_send_failed',
+ /* translators: %s: email name. */
+ sprintf( __( 'The %s email failed with an error before the site sent it. Ask the store owner to check the extensible-abilities log in WooCommerce > Status > Logs.', 'woocommerce' ), $email_name ),
+ array( 'status' => 500 )
+ );
+ }
if ( ! $sent ) {
return new \WP_Error(
@@ -166,26 +194,26 @@ class OrderSendEmail extends AbstractDomainAbility implements AbilityDefinition
}
/**
- * Refuse a status email when the order does not have that status. The email
- * would tell the customer something that is not true.
+ * Refuse an email when the order does not have one of the statuses of the
+ * email. The email would say something about the order that is not true.
*
- * @param \WC_Order $order Order.
- * @param string $email_name Email name from the input.
+ * @param \WC_Order $order Order.
+ * @param string $email_name Email name from the input.
+ * @param array<int, string> $statuses Statuses of the email. Empty for any status.
* @return null|\WP_Error
*/
- private static function get_status_refusal( \WC_Order $order, string $email_name ): ?\WP_Error {
- $required_status = self::REQUIRED_STATUSES[ $email_name ] ?? null;
-
- if ( null === $required_status || $order->has_status( $required_status ) ) {
+ private static function get_status_refusal( \WC_Order $order, string $email_name, array $statuses ): ?\WP_Error {
+ if ( empty( $statuses ) || $order->has_status( $statuses ) ) {
return null;
}
return new \WP_Error(
'woocommerce_ability_order_email_status_mismatch',
sprintf(
- /* translators: 1: email name, 2: order status slug. */
- __( 'The %1$s email only applies to an order with that status, and this order has the "%2$s" status. Send the invoice email, or change the status with the woocommerce/order-update-status ability first.', 'woocommerce' ),
+ /* translators: 1: email name, 2: comma-separated order status slugs, 3: order status slug. */
+ __( 'The %1$s email only applies to an order with the status %2$s, and this order has the "%3$s" status. Send the invoice email, or change the status with the woocommerce/order-update-status ability first.', 'woocommerce' ),
$email_name,
+ implode( ', ', $statuses ),
$order->get_status()
),
array( 'status' => 400 )
@@ -198,6 +226,17 @@ class OrderSendEmail extends AbstractDomainAbility implements AbilityDefinition
* @return array
*/
private static function get_input_schema(): array {
+ $lines = array();
+ foreach ( self::get_emails() as $email_name => $email_args ) {
+ $lines[] = sprintf(
+ /* translators: 1: email name, 2: email description, 3: comma-separated order status slugs. */
+ __( '%1$s: %2$s Statuses: %3$s.', 'woocommerce' ),
+ $email_name,
+ $email_args['description'],
+ empty( $email_args['statuses'] ) ? __( 'any', 'woocommerce' ) : implode( ', ', $email_args['statuses'] )
+ );
+ }
+
return array(
'type' => 'object',
'properties' => array(
@@ -207,8 +246,8 @@ class OrderSendEmail extends AbstractDomainAbility implements AbilityDefinition
),
'email' => array(
'type' => 'string',
- 'description' => __( 'A status email needs the order to have that status.', 'woocommerce' ),
- 'enum' => array_keys( self::EMAIL_CLASSES ),
+ 'description' => __( 'The email to send, from the emails of WooCommerce and extensions. An email is refused for an order without one of its statuses.', 'woocommerce' ) . ' ' . implode( ' ', $lines ),
+ 'enum' => array_keys( self::get_emails() ),
),
),
'required' => array( 'id', 'email' ),
@@ -228,7 +267,7 @@ class OrderSendEmail extends AbstractDomainAbility implements AbilityDefinition
'order_id' => array( 'type' => 'integer' ),
'email' => array(
'type' => 'string',
- 'enum' => array_keys( self::EMAIL_CLASSES ),
+ 'enum' => array_keys( self::get_emails() ),
),
),
'additionalProperties' => false,
diff --git a/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php b/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
index 8d9478a149f..1c13d40700f 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
@@ -1503,6 +1503,182 @@ class ExtensibleAbilitiesTest extends \WC_REST_Unit_Test_Case {
$this->assertFalse( ExtensibleAbilities::is_resource_registered( 'late_resource' ) );
}
+ /**
+ * @testdox Should list the order emails of extensions in order-send-email, send them in their statuses only, send a store email without a billing email, and refuse an unknown email naming the valid ones.
+ */
+ public function test_order_send_email_sends_the_order_emails_of_extensions(): void {
+ $this->register_order_emails();
+ $on_hold_order = \WC_Helper_Order::create_order();
+ $on_hold_order->set_status( OrderStatus::ON_HOLD );
+ $on_hold_order->set_billing_email( 'customer@example.com' );
+ $on_hold_order->save();
+ $pending_order = \WC_Helper_Order::create_order();
+ $mails = array();
+ $capture = static function ( $short_circuit, $atts ) use ( &$mails ) {
+ $mails[] = $atts;
+ return true;
+ };
+ add_filter( 'pre_wp_mail', $capture, 10, 2 );
+
+ $schema = $this->get_ability( 'woocommerce/order-send-email' )['input_schema']['properties']['email'];
+ $on_hold = $this->run_ability(
+ 'woocommerce/order-send-email',
+ array(
+ 'id' => $on_hold_order->get_id(),
+ 'email' => 'test-ext:on-hold',
+ )
+ );
+ $note = $this->run_ability(
+ 'woocommerce/order-send-email',
+ array(
+ 'id' => $pending_order->get_id(),
+ 'email' => 'test-ext:note',
+ )
+ );
+ add_filter( 'woocommerce_order_get_billing_email', '__return_empty_string' );
+ $new_order = $this->run_ability(
+ 'woocommerce/order-send-email',
+ array(
+ 'id' => $pending_order->get_id(),
+ 'email' => 'test-ext:new-order',
+ )
+ );
+ remove_filter( 'woocommerce_order_get_billing_email', '__return_empty_string' );
+ $mismatch = $this->run_ability_response(
+ 'woocommerce/order-send-email',
+ array(
+ 'id' => $pending_order->get_id(),
+ 'email' => 'test-ext:on-hold',
+ )
+ );
+ $unknown = wp_get_ability( 'woocommerce/order-send-email' )->execute(
+ array(
+ 'id' => $pending_order->get_id(),
+ 'email' => 'test-ext:missing',
+ )
+ );
+ remove_filter( 'pre_wp_mail', $capture );
+
+ $this->assertSame( array( 'invoice', 'processing', 'completed', 'test-ext:on-hold', 'test-ext:note', 'test-ext:new-order' ), $schema['enum'] );
+ $this->assertStringContainsString( 'test-ext:on-hold: Tells the customer that the order is on hold. Statuses: on-hold, failed.', $schema['description'] );
+ $this->assertStringContainsString( 'test-ext:note: Sends a reminder note. Statuses: any.', $schema['description'] );
+ $this->assertSame( 'test-ext:on-hold', $on_hold['email'] );
+ $this->assertSame( 'test-ext:note', $note['email'] );
+ $this->assertSame( 'test-ext:new-order', $new_order['email'] );
+ $this->assertCount( 3, $mails );
+ $this->assertSame( 'customer@example.com', $mails[0]['to'] );
+ $this->assertStringContainsString( 'Pay the second payment.', $mails[1]['message'] );
+ $this->assertSame( get_option( 'admin_email' ), $mails[2]['to'] );
+ $this->assertSame( 'woocommerce_ability_order_email_status_mismatch', $mismatch->get_data()['code'] );
+ $this->assertStringContainsString( 'on-hold, failed', $mismatch->get_data()['message'] );
+ $this->assertSame( 'ability_invalid_input', $unknown->get_error_code() );
+ $this->assertStringContainsString( 'test-ext:on-hold', $unknown->get_error_message() );
+ $this->assertStringContainsString( 'test-ext:note', $unknown->get_error_message() );
+ }
+
+ /**
+ * @testdox Should point to the logs, not the mail setup, when the trigger callback of an order email throws.
+ */
+ public function test_order_send_email_reports_a_throwing_trigger_callback(): void {
+ $this->add_test_action(
+ 'woocommerce_extensible_abilities_init',
+ static function () {
+ ExtensibleAbilities::register_order_email(
+ array(
+ 'namespace' => 'test-ext',
+ 'email' => 'broken',
+ 'email_class' => 'WC_Email_Customer_Note',
+ 'description' => 'Throws before it sends.',
+ 'trigger_callback' => static function () {
+ throw new \RuntimeException( 'Broken template.' );
+ },
+ )
+ );
+ }
+ );
+
+ $result = $this->run_ability_response(
+ 'woocommerce/order-send-email',
+ array(
+ 'id' => \WC_Helper_Order::create_order()->get_id(),
+ 'email' => 'test-ext:broken',
+ )
+ );
+
+ $this->assertSame( 'woocommerce_ability_order_email_send_failed', $result->get_data()['code'] );
+ $this->assertStringContainsString( 'WooCommerce > Status > Logs', $result->get_data()['message'] );
+ }
+
+ /**
+ * @testdox Should refuse an order email that is already registered, and keep the first one.
+ */
+ public function test_an_order_email_registered_twice_is_refused(): void {
+ $this->setExpectedIncorrectUsage( ExtensibleAbilities::class . '::register_order_email' );
+ $this->register_order_emails();
+ $this->add_test_action(
+ 'woocommerce_extensible_abilities_init',
+ static function () {
+ ExtensibleAbilities::register_order_email(
+ array(
+ 'namespace' => 'test-ext',
+ 'email' => 'on-hold',
+ 'email_class' => 'WC_Email_Customer_Invoice',
+ 'description' => 'Another email.',
+ )
+ );
+ }
+ );
+
+ $this->get_ability( 'woocommerce/order-send-email' );
+
+ $this->assertSame( 'WC_Email_Customer_On_Hold_Order', ExtensibleAbilities::get_order_emails()['test-ext:on-hold']['email_class'] );
+ }
+
+ /**
+ * Register three order emails of an extension: one sent with the default trigger in two statuses,
+ * one whose trigger takes other arguments, sent in any status, and a store email sent in any status.
+ */
+ private function register_order_emails(): void {
+ $this->add_test_action(
+ 'woocommerce_extensible_abilities_init',
+ static function () {
+ ExtensibleAbilities::register_order_email(
+ array(
+ 'namespace' => 'test-ext',
+ 'email' => 'on-hold',
+ 'email_class' => 'WC_Email_Customer_On_Hold_Order',
+ 'description' => 'Tells the customer that the order is on hold.',
+ 'statuses' => array( 'wc-on-hold', OrderStatus::FAILED ),
+ )
+ );
+ ExtensibleAbilities::register_order_email(
+ array(
+ 'namespace' => 'test-ext',
+ 'email' => 'note',
+ 'email_class' => 'WC_Email_Customer_Note',
+ 'description' => 'Sends a reminder note.',
+ 'trigger_callback' => static function ( \WC_Email $email, \WC_Order $order ) {
+ $email->trigger(
+ array(
+ 'order_id' => $order->get_id(),
+ 'customer_note' => 'Pay the second payment.',
+ )
+ );
+ },
+ )
+ );
+ ExtensibleAbilities::register_order_email(
+ array(
+ 'namespace' => 'test-ext',
+ 'email' => 'new-order',
+ 'email_class' => 'WC_Email_New_Order',
+ 'description' => 'Tells the store about the order.',
+ )
+ );
+ }
+ );
+ }
+
/**
* @testdox Should refuse a resource name made only of digits.
*/
@@ -7698,7 +7874,7 @@ class ExtensibleAbilitiesTest extends \WC_REST_Unit_Test_Case {
private function reset_registries(): void {
global $wp_actions;
- foreach ( array( 'fields', 'validators', 'syncs', 'primes', 'filters' ) as $property ) {
+ foreach ( array( 'fields', 'validators', 'syncs', 'primes', 'filters', 'order_emails' ) as $property ) {
$reflection = new \ReflectionProperty( ExtensibleAbilities::class, $property );
$reflection->setAccessible( true );
$reflection->setValue( null, array() );