Commit 7008e17bd24 for woocommerce

commit 7008e17bd24374d3cdebf4caed3c835595558f7d
Author: iris-woocommerce[bot] <282076412+iris-woocommerce[bot]@users.noreply.github.com>
Date:   Fri Dec 4 11:32:32 2026 -0800

    Abilities: Return the stored order from the order-update ability (#71348)

    * Return the stored order from the order-update ability

    Co-authored-by: matticbot <matticbot@users.noreply.github.com>

    * Note where the product sync test gets its extension field

    Co-authored-by: matticbot <matticbot@users.noreply.github.com>

    * Make the product sync test catch a variation response without the reload

    The variation in the test never loaded its meta before the sync ran, so the
    changed object read the sync's value on first access and the test passed
    without the reload. Writing an extension field on the variation loads its
    meta first.

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

    * Reword the order reload docblock

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

    * Write a field on the parent in the product sync test

    The parent assertion caught a missing reload only because another
    save hook read the parent's meta. Writing a field on the parent makes
    the test load that meta itself.

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

    * Test the order-update reload with a save hook instead of a sync

    Trunk runs no syncs in the order write abilities, so the sync in the
    test never ran. A woocommerce_update_order callback that writes through
    a freshly loaded order now stores the value the response must show.

    Co-Authored-By: Claude Opus 5.5 <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/order-update-returns-stored-order b/plugins/woocommerce/changelog/order-update-returns-stored-order
new file mode 100644
index 00000000000..3bcf602db26
--- /dev/null
+++ b/plugins/woocommerce/changelog/order-update-returns-stored-order
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Show what extensions saved during an order update in the order-update ability response, instead of the old values.
diff --git a/plugins/woocommerce/src/Internal/Abilities/Domain/OrderCreate.php b/plugins/woocommerce/src/Internal/Abilities/Domain/OrderCreate.php
index f380e31083c..b5815502768 100644
--- a/plugins/woocommerce/src/Internal/Abilities/Domain/OrderCreate.php
+++ b/plugins/woocommerce/src/Internal/Abilities/Domain/OrderCreate.php
@@ -261,8 +261,7 @@ class OrderCreate extends ActionableAbility {
 	 * @return array|\WP_Error
 	 */
 	public function prepare_response( $subject ) {
-		$stored = wc_get_order( $subject->get_id() );
-		$order  = self::format_order_for_response( $stored instanceof \WC_Order ? $stored : $subject, array( 'line_items', 'lines' ) );
+		$order = self::format_saved_order_for_response( $subject, array( 'line_items', 'lines' ) );
 		if ( is_wp_error( $order ) ) {
 			return $order;
 		}
diff --git a/plugins/woocommerce/src/Internal/Abilities/Domain/OrderUpdate.php b/plugins/woocommerce/src/Internal/Abilities/Domain/OrderUpdate.php
index abd904c9bf5..150aa9b8b33 100644
--- a/plugins/woocommerce/src/Internal/Abilities/Domain/OrderUpdate.php
+++ b/plugins/woocommerce/src/Internal/Abilities/Domain/OrderUpdate.php
@@ -228,14 +228,14 @@ class OrderUpdate extends ActionableAbility {
 	}

 	/**
-	 * The ability output for the saved order. It includes the lines, so the
-	 * client gets the IDs of the lines it added.
+	 * The ability output for the stored order, so it shows what the syncs wrote.
+	 * It includes the lines, so the client gets the IDs of the lines it added.
 	 *
 	 * @param \WC_Order $subject Saved order.
 	 * @return array|\WP_Error
 	 */
 	public function prepare_response( $subject ) {
-		$order = self::format_order_for_response( $subject, array( 'line_items', 'lines' ) );
+		$order = self::format_saved_order_for_response( $subject, array( 'line_items', 'lines' ) );
 		if ( is_wp_error( $order ) ) {
 			return $order;
 		}
diff --git a/plugins/woocommerce/src/Internal/Abilities/Domain/Traits/OrderAbilityTrait.php b/plugins/woocommerce/src/Internal/Abilities/Domain/Traits/OrderAbilityTrait.php
index 156a59420af..b6ae72b1a1c 100644
--- a/plugins/woocommerce/src/Internal/Abilities/Domain/Traits/OrderAbilityTrait.php
+++ b/plugins/woocommerce/src/Internal/Abilities/Domain/Traits/OrderAbilityTrait.php
@@ -437,14 +437,16 @@ trait OrderAbilityTrait {

 	/**
 	 * Format an order after a save, retaining the saved object if reloading fails.
+	 * The reload picks up what the syncs wrote to storage, which the saved object does not reflect.
 	 *
-	 * @param \WC_Order $order Saved order object.
+	 * @param \WC_Order $order    Saved order object.
+	 * @param string[]  $includes Optional parts, as for format_order_for_response().
 	 * @return array|\WP_Error
 	 */
-	protected static function format_saved_order_for_response( \WC_Order $order ) {
+	protected static function format_saved_order_for_response( \WC_Order $order, array $includes = array() ) {
 		$stored = wc_get_order( $order->get_id() );

-		return self::format_order_for_response( $stored instanceof \WC_Order ? $stored : $order, array() );
+		return self::format_order_for_response( $stored instanceof \WC_Order ? $stored : $order, $includes );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php b/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
index 8c755cf4c08..e221a598730 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
@@ -6815,6 +6815,95 @@ class ExtensibleAbilitiesTest extends \WC_REST_Unit_Test_Case {



+	/**
+	 * @testdox Should return from order-update what a save hook stored without the changed order object.
+	 */
+	public function test_order_update_returns_what_a_save_hook_stored(): void {
+		$this->add_test_action(
+			'woocommerce_extensible_abilities_init',
+			static function () {
+				ExtensibleAbilities::register_field(
+					array(
+						'resource'      => 'order',
+						'namespace'     => 'test-ext',
+						'field'         => 'priority',
+						'output_schema' => array( 'type' => 'string' ),
+						'get_callback'  => static fn( \WC_Order $order ) => (string) $order->get_meta( '_test_priority' ),
+					)
+				);
+			}
+		);
+		$this->reset_registries();
+		AbilitiesLoader::init_extensions();
+		$order  = \WC_Helper_Order::create_order();
+		$hooked = false;
+		$this->add_test_action(
+			'woocommerce_update_order',
+			static function ( $order_id ) use ( &$hooked ) {
+				if ( $hooked ) {
+					return;
+				}
+				$hooked = true;
+				$stored = wc_get_order( $order_id );
+				$stored->update_meta_data( '_test_priority', 'hooked' );
+				$stored->save();
+			}
+		);
+
+		$output = $this->run_ability(
+			'woocommerce/order-update',
+			array(
+				'id'            => $order->get_id(),
+				'customer_note' => 'Leave at the door.',
+			)
+		);
+
+		$this->assertSame( 'hooked', $output['order']['extensions']['test-ext']['priority'] );
+		$this->assertSame( 'Leave at the door.', wc_get_order( $order->get_id() )->get_customer_note() );
+	}
+
+	/**
+	 * @testdox Should return from product-update what a sync stored on the product and its variations without the changed objects.
+	 */
+	public function test_product_update_returns_what_a_sync_stored(): void {
+		// register_test_fields() registers the test-ext.code field, read from _test_code, for products and variations.
+		$created = $this->run_ability( 'woocommerce/product-create', $this->get_shirt_input() );
+		$this->register_sync(
+			'product',
+			'test-ext',
+			static function ( array $saved ) {
+				foreach ( $saved as $object ) {
+					$stored = wc_get_product( $object->get_id() );
+					$stored->update_meta_data( '_test_code', 'synced-' . $object->get_id() );
+					$stored->save();
+				}
+				return null;
+			}
+		);
+		$this->reset_registries();
+		AbilitiesLoader::init_extensions();
+		$variation_id = $created['product']['variation_ids'][0];
+
+		// Writing a field loads each object's meta, so a response from the changed objects would miss the sync's values.
+		$output = $this->run_ability(
+			'woocommerce/product-update',
+			array(
+				'id'         => $created['product']['id'],
+				'extensions' => array( 'test-ext' => array( 'color' => 'red' ) ),
+				'variations' => array(
+					array(
+						'id'         => $variation_id,
+						'extensions' => array( 'test-ext' => array( 'color' => 'red' ) ),
+					),
+				),
+			)
+		);
+
+		$this->assertSame( 'synced-' . $created['product']['id'], $output['product']['extensions']['test-ext']['code'] );
+		$this->assertSame( $variation_id, $output['variations'][0]['id'] );
+		$this->assertSame( 'synced-' . $variation_id, $output['variations'][0]['extensions']['test-ext']['code'] );
+	}
+
 	/**
 	 * @testdox Should recalculate with calculate_totals() after the save when the feature is off.
 	 */