Automattic\WooCommerce\StoreApi\Schemas\V1

OrderSchema::get_item_response()publicWC 1.0

Get an order for response.

Method of the class: OrderSchema{}

No Hooks.

Return

Array.

Usage

$OrderSchema = new OrderSchema();
$OrderSchema->get_item_response( $order );
$order(\WC_Order) (required)
Order instance.

OrderSchema::get_item_response() code WC 9.3.3

public function get_item_response( $order ) {
	$order_id                 = $order->get_id();
	$errors                   = [];
	$failed_order_stock_error = $this->order_controller->get_failed_order_stock_error( $order_id );
	if ( $failed_order_stock_error ) {
		$errors[] = $failed_order_stock_error;
	}

	return [
		'id'                   => $order_id,
		'status'               => $order->get_status(),
		'items'                => $this->get_item_responses_from_schema( $this->item_schema, $order->get_items() ),
		'coupons'              => $this->get_item_responses_from_schema( $this->coupon_schema, $order->get_items( 'coupon' ) ),
		'fees'                 => $this->get_item_responses_from_schema( $this->fee_schema, $order->get_items( 'fee' ) ),
		'totals'               => (object) $this->prepare_currency_response( $this->get_totals( $order ) ),
		'shipping_address'     => (object) $this->shipping_address_schema->get_item_response( $order ),
		'billing_address'      => (object) $this->billing_address_schema->get_item_response( $order ),
		'needs_payment'        => $order->needs_payment(),
		'needs_shipping'       => $order->needs_shipping_address(),
		'payment_requirements' => $this->extend->get_payment_requirements(),
		'errors'               => $errors,
	];
}