diff --git a/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php b/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php index 6411a920afa..01a67019e4f 100644 --- a/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php +++ b/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php @@ -212,19 +212,19 @@ class WC_REST_Orders_V2_Controller extends WC_REST_CRUD_Controller { * Merge the `$formatted_meta_data` `display_key` and `display_value` attribute values into the corresponding * {@link WC_Meta_Data}. Returns the merged array. * - * @param WC_Meta_Data $meta_item An object from {@link WC_Order_Item::get_meta_data()}. - * @param Object[] $formatted_meta_data An object result from {@link WC_Order_Item::get_formatted_meta_data}. + * @param WC_Meta_Data $meta_item An object from {@link WC_Order_Item::get_meta_data()}. + * @param array $formatted_meta_data An object result from {@link WC_Order_Item::get_formatted_meta_data}. * The keys are the IDs of {@link WC_Meta_Data}. * * @return array */ private function merge_meta_item_with_formatted_meta_display_attributes( $meta_item, $formatted_meta_data ) { $result = array( - 'id' => $meta_item->id, - 'key' => $meta_item->key, - 'value' => $meta_item->value, - 'display_key' => null, - 'display_value' => null, + 'id' => $meta_item->id, + 'key' => $meta_item->key, + 'value' => $meta_item->value, + 'display_key' => $meta_item->key, // Default to original key, in case a formatted key is not available. + 'display_value' => $meta_item->value, // Default to original value, in case a formatted value is not available. ); if ( array_key_exists( $meta_item->id, $formatted_meta_data ) ) { diff --git a/tests/legacy/unit-tests/rest-api/Tests/Version3/orders.php b/tests/legacy/unit-tests/rest-api/Tests/Version3/orders.php index ce6fee73f38..e6ec0cafb1d 100644 --- a/tests/legacy/unit-tests/rest-api/Tests/Version3/orders.php +++ b/tests/legacy/unit-tests/rest-api/Tests/Version3/orders.php @@ -337,6 +337,8 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case { $this->assertEquals( $expected_meta_item->id, $actual_shipping_line_meta_data[ $index ]['id'] ); $this->assertEquals( $expected_meta_item->key, $actual_shipping_line_meta_data[ $index ]['key'] ); $this->assertEquals( $expected_meta_item->value, $actual_shipping_line_meta_data[ $index ]['value'] ); + $this->assertEquals( $expected_meta_item->key, $actual_shipping_line_meta_data[ $index ]['display_key'] ); + $this->assertEquals( $expected_meta_item->value, $actual_shipping_line_meta_data[ $index ]['display_value'] ); } }