WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

WC_REST_Orders_V2_Controller::get_formatted_item_data() protected WC 3.0.0

Get formatted item data.

{} Это метод класса: WC_REST_Orders_V2_Controller{}

Хуков нет.

Возвращает

Массив.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_formatted_item_data( $object );
$object(WC_Data) (обязательный)
WC_Data instance.

Список изменений

С версии 3.0.0 Введена.

Код WC_REST_Orders_V2_Controller::get_formatted_item_data() WC 4.7.1

<?php
protected function get_formatted_item_data( $object ) {
	$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 line items.
	foreach ( $format_line_items as $key ) {
		$data[ $key ] = array_values( array_map( array( $this, 'get_order_item_data' ), $data[ $key ] ) );
	}

	// 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(
		'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'],
		'line_items'           => $data['line_items'],
		'tax_lines'            => $data['tax_lines'],
		'shipping_lines'       => $data['shipping_lines'],
		'fee_lines'            => $data['fee_lines'],
		'coupon_lines'         => $data['coupon_lines'],
		'refunds'              => $data['refunds'],
	);
}