Use default value if formatted value is not available
This commit is contained in:
parent
8e12de5d3c
commit
c01f32a390
|
@ -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 ) ) {
|
||||
|
|
|
@ -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'] );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue