Commit 00f9cd40560 for woocommerce
commit 00f9cd40560de7bbbef77b38d22ffabc26ac193c
Author: Cvetan Cvetanov <cvetan.cvetanov@automattic.com>
Date: Wed Jul 15 16:21:52 2026 +0300
Fix nullable parent names in REST API order items (#66636)
* Fix nullable parent names in REST API order items
* Add changelog entry for nullable order parent names
diff --git a/plugins/woocommerce/changelog/fix-28861-nullable-parent-name b/plugins/woocommerce/changelog/fix-28861-nullable-parent-name
new file mode 100644
index 00000000000..9625646a995
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-28861-nullable-parent-name
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Allow null parent names in REST API order line items.
diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php
index fa8bde2a2a3..89d5ce9303e 100644
--- a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php
+++ b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php
@@ -1506,7 +1506,7 @@ class WC_REST_Orders_V2_Controller extends WC_REST_CRUD_Controller {
),
'parent_name' => array(
'description' => __( 'Parent product name if the product is a variation.', 'woocommerce' ),
- 'type' => 'string',
+ 'type' => array( 'string', 'null' ),
'context' => array( 'view', 'edit' ),
),
'product_id' => array(
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/orders.php b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/orders.php
index 2f0c7ca7267..bbf402d4dea 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/orders.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/orders.php
@@ -798,7 +798,7 @@ class WC_Tests_API_Orders_V2 extends WC_REST_Unit_Test_Case {
}
/**
- * Test the order line items schema.
+ * @testdox Should expose the expected order line item schema.
*/
public function test_order_line_items_schema() {
wp_set_current_user( $this->user );
@@ -813,6 +813,7 @@ class WC_Tests_API_Orders_V2 extends WC_REST_Unit_Test_Case {
$this->assertArrayHasKey( 'id', $line_item_properties );
$this->assertArrayHasKey( 'meta_data', $line_item_properties );
$this->assertArrayHasKey( 'parent_name', $line_item_properties );
+ $this->assertSame( array( 'string', 'null' ), $line_item_properties['parent_name']['type'] );
$meta_data_item_properties = $line_item_properties['meta_data']['items']['properties'];
$this->assertEquals( 5, count( $meta_data_item_properties ) );
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/orders.php b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/orders.php
index fa45ad97373..9d3c85fa123 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/orders.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/orders.php
@@ -577,6 +577,33 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
$this->assertEquals( 'Face', $data['billing']['last_name'] );
}
+ /**
+ * @testdox Should accept a null parent name when updating a non-variation line item.
+ */
+ public function test_update_order_accepts_null_parent_name(): void {
+ wp_set_current_user( $this->user );
+ $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
+ $order = OrderHelper::create_order( 1, $product );
+ $line_item = current( $order->get_items( 'line_item' ) );
+ $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() );
+ $request->set_body_params(
+ array(
+ 'line_items' => array(
+ array(
+ 'id' => $line_item->get_id(),
+ 'parent_name' => null,
+ ),
+ ),
+ )
+ );
+
+ $response = $this->server->dispatch( $request );
+ $data = $response->get_data();
+
+ $this->assertSame( 200, $response->get_status() );
+ $this->assertNull( $data['line_items'][0]['parent_name'] );
+ }
+
/**
* Tests updating an order and removing items.
*
@@ -1153,7 +1180,7 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
}
/**
- * Test the order line items schema.
+ * @testdox Should expose the expected order line item schema.
*/
public function test_order_line_items_schema() {
wp_set_current_user( $this->user );
@@ -1168,6 +1195,7 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
$this->assertArrayHasKey( 'id', $line_item_properties );
$this->assertArrayHasKey( 'meta_data', $line_item_properties );
$this->assertArrayHasKey( 'parent_name', $line_item_properties );
+ $this->assertSame( array( 'string', 'null' ), $line_item_properties['parent_name']['type'] );
$meta_data_item_properties = $line_item_properties['meta_data']['items']['properties'];
$this->assertEquals( 5, count( $meta_data_item_properties ) );