WordPress at a glance
function is not described

Automattic\WooCommerce\Admin\API

Orders::get_formatted_item_data() protected WC 1.0

Get formatted item data.

{} It's a method of the class: Orders{}

No Hooks.

Return

Array. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_formatted_item_data( $object );
$object(WC_Data) (required)
WC_Data instance.

Code of Orders::get_formatted_item_data() WC 5.2.2

<?php
protected function get_formatted_item_data( $object ) {
	$fields = false;
	// Determine if the response fields were specified.
	if ( ! empty( $this->request['_fields'] ) ) {
		$fields = wp_parse_list( $this->request['_fields'] );

		if ( 0 === count( $fields ) ) {
			$fields = false;
		} else {
			$fields = array_map( 'trim', $fields );
		}
	}

	// Initially skip line items if we can.
	$using_order_class_override = is_a( $object, '\Automattic\WooCommerce\Admin\Overrides\Order' );
	if ( $using_order_class_override ) {
		$data = $object->get_data_without_line_items();
	} else {
		$data = $object->get_data();
	}

	$format_decimal    = array( 'discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax' );
	$format_date       = array( 'date_created', 'date_modified', 'date_completed', 'date_paid' );
	$format_line_items = array( 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines' );

	// Format decimal values.
	foreach ( $format_decimal as $key ) {
		$data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] );
	}

	// Format date values.
	foreach ( $format_date as $key ) {
		$datetime              = $data[ $key ];
		$data[ $key ]          = wc_rest_prepare_date_response( $datetime, false );
		$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
	}

	// Format the order status.
	$data['status'] = 'wc-' === substr( $data['status'], 0, 3 ) ? substr( $data['status'], 3 ) : $data['status'];

	// Format requested line items.
	$formatted_line_items = array();

	foreach ( $format_line_items as $key ) {
		if ( false === $fields || in_array( $key, $fields ) ) {
			if ( $using_order_class_override ) {
				$line_item_data = $object->get_line_item_data( $key );
			} else {
				$line_item_data = $data[ $key ];
			}
			$formatted_line_items[ $key ] = array_values( array_map( array( $this, 'get_order_item_data' ), $line_item_data ) );
		}
	}

	// Refunds.
	$data['refunds'] = array();
	foreach ( $object->get_refunds() as $refund ) {
		$data['refunds'][] = array(
			'id'     => $refund->get_id(),
			'reason' => $refund->get_reason() ? $refund->get_reason() : '',
			'total'  => '-' . wc_format_decimal( $refund->get_amount(), $this->request['dp'] ),
		);
	}

	return array_merge(
		array(
			'id'                   => $object->get_id(),
			'parent_id'            => $data['parent_id'],
			'number'               => $data['number'],
			'order_key'            => $data['order_key'],
			'created_via'          => $data['created_via'],
			'version'              => $data['version'],
			'status'               => $data['status'],
			'currency'             => $data['currency'],
			'date_created'         => $data['date_created'],
			'date_created_gmt'     => $data['date_created_gmt'],
			'date_modified'        => $data['date_modified'],
			'date_modified_gmt'    => $data['date_modified_gmt'],
			'discount_total'       => $data['discount_total'],
			'discount_tax'         => $data['discount_tax'],
			'shipping_total'       => $data['shipping_total'],
			'shipping_tax'         => $data['shipping_tax'],
			'cart_tax'             => $data['cart_tax'],
			'total'                => $data['total'],
			'total_tax'            => $data['total_tax'],
			'prices_include_tax'   => $data['prices_include_tax'],
			'customer_id'          => $data['customer_id'],
			'customer_ip_address'  => $data['customer_ip_address'],
			'customer_user_agent'  => $data['customer_user_agent'],
			'customer_note'        => $data['customer_note'],
			'billing'              => $data['billing'],
			'shipping'             => $data['shipping'],
			'payment_method'       => $data['payment_method'],
			'payment_method_title' => $data['payment_method_title'],
			'transaction_id'       => $data['transaction_id'],
			'date_paid'            => $data['date_paid'],
			'date_paid_gmt'        => $data['date_paid_gmt'],
			'date_completed'       => $data['date_completed'],
			'date_completed_gmt'   => $data['date_completed_gmt'],
			'cart_hash'            => $data['cart_hash'],
			'meta_data'            => $data['meta_data'],
			'refunds'              => $data['refunds'],
		),
		$formatted_line_items
	);
}