add_meta_data( 'testkey', '1' ); $item->add_meta_data( 'testkey', '2' ); $item->add_meta_data( 'otherkey', 'val' ); $item->save(); $meta = new WC_Order_Item_Meta( $item ); $expected = array(); foreach ( $item->get_meta_data() as $metadata ) { $expected[ $metadata->id ] = array( 'key' => $metadata->key, 'label' => wc_attribute_label( $metadata->key, null ), 'value' => $metadata->value, ); } $result = $meta->get_formatted(); $this->assertEquals( 3, count( $result ) ); $this->assertEquals( $expected, $result ); // Clean up. $item->delete( true ); } }