Passed
Push — master ( f8a28a...ab42dc )
by Mike
04:36
created

Orders::save_object()   C

Complexity

Conditions 14
Paths 53

Size

Total Lines 34
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 20
nc 53
nop 2
dl 0
loc 34
rs 6.2666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * REST API Orders controller
4
 *
5
 * Handles requests to the /orders endpoint.
6
 *
7
 * @package WooCommerce/RestApi
8
 */
9
10
namespace WooCommerce\RestApi\Controllers\Version4;
11
12
defined( 'ABSPATH' ) || exit;
13
14
use WooCommerce\RestApi\Controllers\Version4\Schema\OrderRequest;
15
use WooCommerce\RestApi\Controllers\Version4\Schema\OrderResponse;
16
17
/**
18
 * REST API Orders controller class.
19
 */
20
class Orders extends AbstractObjectsController {
21
22
	/**
23
	 * Route base.
24
	 *
25
	 * @var string
26
	 */
27
	protected $rest_base = 'orders';
28
29
	/**
30
	 * Post type.
31
	 *
32
	 * @var string
33
	 */
34
	protected $post_type = 'shop_order';
35
36
	/**
37
	 * If object is hierarchical.
38
	 *
39
	 * @var bool
40
	 */
41
	protected $hierarchical = true;
42
43
	/**
44
	 * Stores the request.
45
	 *
46
	 * @var array
47
	 */
48
	protected $request = array();
49
50
	/**
51
	 * Get object. Return false if object is not of required type.
52
	 *
53
	 * @since  3.0.0
54
	 * @param  int $id Object ID.
55
	 * @return \WC_Data|bool
56
	 */
57
	protected function get_object( $id ) {
58
		$order = wc_get_order( $id );
59
		// In case id is a refund's id (or it's not an order at all), don't expose it via /orders/ path.
60
		if ( ! $order || 'shop_order_refund' === $order->get_type() ) {
61
			return false;
62
		}
63
64
		return $order;
65
	}
66
67
	/**
68
	 * Expands an order item to get its data.
69
	 *
70
	 * @param \WC_Order_item $item Order item data.
71
	 * @return array
72
	 */
73
	protected function get_order_item_data( $item ) {
74
		$data           = $item->get_data();
75
		$format_decimal = array( 'subtotal', 'subtotal_tax', 'total', 'total_tax', 'tax_total', 'shipping_tax_total' );
76
77
		// Format decimal values.
78
		foreach ( $format_decimal as $key ) {
79
			if ( isset( $data[ $key ] ) ) {
80
				$data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] );
81
			}
82
		}
83
84
		// Add SKU and PRICE to products.
85
		if ( is_callable( array( $item, 'get_product' ) ) ) {
86
			$data['sku']   = $item->get_product() ? $item->get_product()->get_sku() : null;
0 ignored issues
show
Bug introduced by
The method get_product() does not exist on WC_Order_Item. Did you maybe mean get_prop()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
			$data['sku']   = $item->/** @scrutinizer ignore-call */ get_product() ? $item->get_product()->get_sku() : null;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
			$data['price'] = $item->get_quantity() ? $item->get_total() / $item->get_quantity() : 0;
0 ignored issues
show
Bug introduced by
The method get_total() does not exist on WC_Order_Item. It seems like you code against a sub-type of said class. However, the method does not exist in WC_Order_Item_Tax or WC_Order_Item_Coupon. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
			$data['price'] = $item->get_quantity() ? $item->/** @scrutinizer ignore-call */ get_total() / $item->get_quantity() : 0;
Loading history...
88
		}
89
90
		// Format taxes.
91
		if ( ! empty( $data['taxes']['total'] ) ) {
92
			$taxes = array();
93
94
			foreach ( $data['taxes']['total'] as $tax_rate_id => $tax ) {
95
				$taxes[] = array(
96
					'id'       => $tax_rate_id,
97
					'total'    => $tax,
98
					'subtotal' => isset( $data['taxes']['subtotal'][ $tax_rate_id ] ) ? $data['taxes']['subtotal'][ $tax_rate_id ] : '',
99
				);
100
			}
101
			$data['taxes'] = $taxes;
102
		} elseif ( isset( $data['taxes'] ) ) {
103
			$data['taxes'] = array();
104
		}
105
106
		// Remove names for coupons, taxes and shipping.
107
		if ( isset( $data['code'] ) || isset( $data['rate_code'] ) || isset( $data['method_title'] ) ) {
108
			unset( $data['name'] );
109
		}
110
111
		// Remove props we don't want to expose.
112
		unset( $data['order_id'] );
113
		unset( $data['type'] );
114
115
		return $data;
116
	}
117
118
	/**
119
	 * Prepare a single order output for response.
120
	 *
121
	 * @since  3.0.0
122
	 * @param  \WC_Data         $object  Object data.
123
	 * @param  \WP_REST_Request $request Request object.
124
	 * @return \WP_REST_Response
125
	 */
126
	public function prepare_object_for_response( $object, $request ) {
127
		$context        = ! empty( $request['context'] ) ? $request['context'] : 'view';
128
		$order_response = new OrderResponse();
129
130
		if ( ! is_null( $request['dp'] ) ) {
131
			$order_response->set_dp( $request['dp'] );
132
		}
133
134
		$data     = $order_response->prepare_response( $object, $context );
135
		$data     = $this->add_additional_fields_to_object( $data, $request );
136
		$data     = $this->filter_response_by_context( $data, $context );
137
		$response = rest_ensure_response( $data );
138
		$response->add_links( $this->prepare_links( $object, $request ) );
139
140
		/**
141
		 * Filter the data for a response.
142
		 *
143
		 * The dynamic portion of the hook name, $this->post_type,
144
		 * refers to object type being prepared for the response.
145
		 *
146
		 * @param \WP_REST_Response $response The response object.
147
		 * @param \WC_Data          $object   Object data.
148
		 * @param \WP_REST_Request  $request  Request object.
149
		 */
150
		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
151
	}
152
153
	/**
154
	 * Prepare links for the request.
155
	 *
156
	 * @param \WC_Data         $object  Object data.
157
	 * @param \WP_REST_Request $request Request object.
158
	 * @return array                   Links for the given post.
159
	 */
160
	protected function prepare_links( $object, $request ) {
161
		$links = array(
162
			'self'       => array(
163
				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ),
164
			),
165
			'collection' => array(
166
				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
167
			),
168
		);
169
170
		if ( 0 !== (int) $object->get_customer_id() ) {
0 ignored issues
show
Bug introduced by
The method get_customer_id() does not exist on WC_Data. It seems like you code against a sub-type of WC_Data such as WC_Order. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

170
		if ( 0 !== (int) $object->/** @scrutinizer ignore-call */ get_customer_id() ) {
Loading history...
171
			$links['customer'] = array(
172
				'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $object->get_customer_id() ) ),
173
			);
174
		}
175
176
		if ( 0 !== (int) $object->get_parent_id() ) {
0 ignored issues
show
Bug introduced by
The method get_parent_id() does not exist on WC_Data. It seems like you code against a sub-type of WC_Data such as WC_Product or WC_Abstract_Order. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

176
		if ( 0 !== (int) $object->/** @scrutinizer ignore-call */ get_parent_id() ) {
Loading history...
177
			$links['up'] = array(
178
				'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $object->get_parent_id() ) ),
179
			);
180
		}
181
182
		return $links;
183
	}
184
185
	/**
186
	 * Prepare objects query.
187
	 *
188
	 * @since  3.0.0
189
	 * @param  \WP_REST_Request $request Full details about the request.
190
	 * @return array
191
	 */
192
	protected function prepare_objects_query( $request ) {
193
		global $wpdb;
194
195
		// This is needed to get around an array to string notice in \WC_REST_Orders_V2_Controller::prepare_objects_query.
196
		$statuses = $request['status'];
197
		unset( $request['status'] );
198
		$args = parent::prepare_objects_query( $request );
199
200
		$args['post_status'] = array();
201
		foreach ( $statuses as $status ) {
202
			if ( in_array( $status, $this->get_order_statuses(), true ) ) {
203
				$args['post_status'][] = 'wc-' . $status;
204
			} elseif ( 'any' === $status ) {
205
				// Set status to "any" and short-circuit out.
206
				$args['post_status'] = 'any';
207
				break;
208
			} else {
209
				$args['post_status'][] = $status;
210
			}
211
		}
212
213
		// Put the statuses back for further processing (next/prev links, etc).
214
		$request['status'] = $statuses;
215
216
		// Customer.
217
		if ( isset( $request['customer'] ) ) {
218
			if ( ! empty( $args['meta_query'] ) ) {
219
				$args['meta_query'] = array(); // WPCS: slow query ok.
220
			}
221
222
			$args['meta_query'][] = array(
223
				'key'   => '_customer_user',
224
				'value' => $request['customer'],
225
				'type'  => 'NUMERIC',
226
			);
227
		}
228
229
		// Search by product.
230
		if ( ! empty( $request['product'] ) ) {
231
			$order_ids = $wpdb->get_col(
232
				$wpdb->prepare(
233
					"SELECT order_id
234
					FROM {$wpdb->prefix}woocommerce_order_items
235
					WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key = '_product_id' AND meta_value = %d )
236
					AND order_item_type = 'line_item'",
237
					$request['product']
238
				)
239
			);
240
241
			// Force WP_Query return empty if don't found any order.
242
			$order_ids = ! empty( $order_ids ) ? $order_ids : array( 0 );
243
244
			$args['post__in'] = $order_ids;
245
		}
246
247
		// Search.
248
		if ( ! empty( $args['s'] ) ) {
249
			$order_ids = wc_order_search( $args['s'] );
250
251
			if ( ! empty( $order_ids ) ) {
252
				unset( $args['s'] );
253
				$args['post__in'] = array_merge( $order_ids, array( 0 ) );
254
			}
255
		}
256
257
		// Search by partial order number.
258
		if ( ! empty( $request['number'] ) ) {
259
			$partial_number = trim( $request['number'] );
260
			$limit          = intval( $args['posts_per_page'] );
261
			$order_ids      = $wpdb->get_col(
262
				$wpdb->prepare(
263
					"SELECT ID
264
					FROM {$wpdb->prefix}posts
265
					WHERE post_type = 'shop_order'
266
					AND ID LIKE %s
267
					LIMIT %d",
268
					$wpdb->esc_like( absint( $partial_number ) ) . '%',
269
					$limit
270
				)
271
			);
272
273
			// Force \WP_Query return empty if don't found any order.
274
			$order_ids        = empty( $order_ids ) ? array( 0 ) : $order_ids;
275
			$args['post__in'] = $order_ids;
276
		}
277
278
		return $args;
279
	}
280
281
	/**
282
	 * Prepare a single order for create or update.
283
	 *
284
	 * @throws \WC_REST_Exception When fails to set any item.
285
	 * @param  \WP_REST_Request $request Request object.
286
	 * @param  bool             $creating If is creating a new object.
287
	 * @return \WP_Error|\WC_Data
288
	 */
289
	protected function prepare_object_for_database( $request, $creating = false ) {
290
		try {
291
			$order_request = new OrderRequest( $request );
292
			$order         = $order_request->prepare_object();
293
		} catch ( \WC_REST_Exception $e ) {
294
			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
295
		}
296
297
		/**
298
		 * Filters an object before it is inserted via the REST API.
299
		 *
300
		 * The dynamic portion of the hook name, `$this->post_type`,
301
		 * refers to the object type slug.
302
		 *
303
		 * @param \WC_Data         $order    Object object.
304
		 * @param \WP_REST_Request $request  Request object.
305
		 * @param bool            $creating If is creating a new object.
306
		 */
307
		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating );
308
	}
309
310
	/**
311
	 * Save an object data.
312
	 *
313
	 * @param  \WP_REST_Request $request  Full details about the request.
314
	 * @param  bool             $creating If is creating a new object.
315
	 * @return \WC_Data|\WP_Error
316
	 * @throws \WC_REST_Exception But all errors are validated before returning any data.
317
	 */
318
	protected function save_object( $request, $creating = false ) {
319
		try {
320
			$object = $this->prepare_object_for_database( $request, $creating );
321
322
			if ( is_wp_error( $object ) ) {
323
				return $object;
324
			}
325
326
			// Make sure gateways are loaded so hooks from gateways fire on save/create.
327
			WC()->payment_gateways();
328
329
			if ( $creating ) {
330
				$object->set_created_via( 'rest-api' );
0 ignored issues
show
Bug introduced by
The method set_created_via() does not exist on WC_Data. It seems like you code against a sub-type of WC_Data such as WC_Order. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

330
				$object->/** @scrutinizer ignore-call */ 
331
             set_created_via( 'rest-api' );
Loading history...
Bug introduced by
The method set_created_via() does not exist on WP_Error. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

330
				$object->/** @scrutinizer ignore-call */ 
331
             set_created_via( 'rest-api' );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
331
				$object->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
0 ignored issues
show
Bug introduced by
The method set_prices_include_tax() does not exist on WP_Error. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

331
				$object->/** @scrutinizer ignore-call */ 
332
             set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method set_prices_include_tax() does not exist on WC_Data. It seems like you code against a sub-type of WC_Data such as WC_Abstract_Order. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

331
				$object->/** @scrutinizer ignore-call */ 
332
             set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
Loading history...
332
				$object->calculate_totals();
0 ignored issues
show
Bug introduced by
The method calculate_totals() does not exist on WP_Error. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

332
				$object->/** @scrutinizer ignore-call */ 
333
             calculate_totals();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method calculate_totals() does not exist on WC_Data. It seems like you code against a sub-type of WC_Data such as WC_Abstract_Order. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

332
				$object->/** @scrutinizer ignore-call */ 
333
             calculate_totals();
Loading history...
333
			} else {
334
				// If items have changed, recalculate order totals.
335
				if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) {
336
					$object->calculate_totals( true );
337
				}
338
			}
339
340
			$object->save();
0 ignored issues
show
Bug introduced by
The method save() does not exist on WP_Error. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

340
			$object->/** @scrutinizer ignore-call */ 
341
            save();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
341
342
			// Actions for after the order is saved.
343
			if ( true === $request['set_paid'] && ( $creating || $object->needs_payment() ) ) {
0 ignored issues
show
Bug introduced by
The method needs_payment() does not exist on WP_Error. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

343
			if ( true === $request['set_paid'] && ( $creating || $object->/** @scrutinizer ignore-call */ needs_payment() ) ) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method needs_payment() does not exist on WC_Data. It seems like you code against a sub-type of WC_Data such as WC_Order. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

343
			if ( true === $request['set_paid'] && ( $creating || $object->/** @scrutinizer ignore-call */ needs_payment() ) ) {
Loading history...
344
				$object->payment_complete();
0 ignored issues
show
Bug introduced by
The method payment_complete() does not exist on WC_Data. It seems like you code against a sub-type of WC_Data such as WC_Order. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

344
				$object->/** @scrutinizer ignore-call */ 
345
             payment_complete();
Loading history...
Bug introduced by
The method payment_complete() does not exist on WP_Error. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

344
				$object->/** @scrutinizer ignore-call */ 
345
             payment_complete();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
345
			}
346
347
			return $this->get_object( $object->get_id() );
0 ignored issues
show
Bug introduced by
The method get_id() does not exist on WP_Error. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

347
			return $this->get_object( $object->/** @scrutinizer ignore-call */ get_id() );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
348
		} catch ( \WC_Data_Exception $e ) {
349
			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
350
		} catch ( \WC_REST_Exception $e ) {
351
			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
352
		}
353
	}
354
355
	/**
356
	 * Get order statuses without prefixes.
357
	 *
358
	 * @return array
359
	 */
360
	protected function get_order_statuses() {
361
		$order_statuses = array();
362
363
		foreach ( array_keys( wc_get_order_statuses() ) as $status ) {
364
			$order_statuses[] = str_replace( 'wc-', '', $status );
365
		}
366
367
		return $order_statuses;
368
	}
369
370
	/**
371
	 * Get the Order's schema, conforming to JSON Schema.
372
	 *
373
	 * @return array
374
	 */
375
	public function get_item_schema() {
376
		$schema = array(
377
			'$schema'    => 'http://json-schema.org/draft-04/schema#',
378
			'title'      => $this->post_type,
379
			'type'       => 'object',
380
			'properties' => array(
381
				'id'                   => array(
382
					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
383
					'type'        => 'integer',
384
					'context'     => array( 'view', 'edit' ),
385
					'readonly'    => true,
386
				),
387
				'parent_id'            => array(
388
					'description' => __( 'Parent order ID.', 'woocommerce' ),
389
					'type'        => 'integer',
390
					'context'     => array( 'view', 'edit' ),
391
				),
392
				'number'               => array(
393
					'description' => __( 'Order number.', 'woocommerce' ),
394
					'type'        => 'string',
395
					'context'     => array( 'view', 'edit' ),
396
					'readonly'    => true,
397
				),
398
				'order_key'            => array(
399
					'description' => __( 'Order key.', 'woocommerce' ),
400
					'type'        => 'string',
401
					'context'     => array( 'view', 'edit' ),
402
					'readonly'    => true,
403
				),
404
				'created_via'          => array(
405
					'description' => __( 'Shows where the order was created.', 'woocommerce' ),
406
					'type'        => 'string',
407
					'context'     => array( 'view', 'edit' ),
408
					'readonly'    => true,
409
				),
410
				'version'              => array(
411
					'description' => __( 'Version of WooCommerce which last updated the order.', 'woocommerce' ),
412
					'type'        => 'integer',
413
					'context'     => array( 'view', 'edit' ),
414
					'readonly'    => true,
415
				),
416
				'status'               => array(
417
					'description' => __( 'Order status.', 'woocommerce' ),
418
					'type'        => 'string',
419
					'default'     => 'pending',
420
					'enum'        => $this->get_order_statuses(),
421
					'context'     => array( 'view', 'edit' ),
422
				),
423
				'currency'             => array(
424
					'description' => __( 'Currency the order was created with, in ISO format.', 'woocommerce' ),
425
					'type'        => 'string',
426
					'default'     => get_woocommerce_currency(),
427
					'enum'        => array_keys( get_woocommerce_currencies() ),
428
					'context'     => array( 'view', 'edit' ),
429
				),
430
				'currency_symbol'      => array(
431
					'description' => __( 'Currency symbol.', 'woocommerce' ),
432
					'type'        => 'string',
433
					'context'     => array( 'view', 'edit' ),
434
					'readonly'    => true,
435
				),
436
				'date_created'         => array(
437
					'description' => __( "The date the order was created, in the site's timezone.", 'woocommerce' ),
438
					'type'        => 'date-time',
439
					'context'     => array( 'view', 'edit' ),
440
					'readonly'    => true,
441
				),
442
				'date_created_gmt'     => array(
443
					'description' => __( 'The date the order was created, as GMT.', 'woocommerce' ),
444
					'type'        => 'date-time',
445
					'context'     => array( 'view', 'edit' ),
446
					'readonly'    => true,
447
				),
448
				'date_modified'        => array(
449
					'description' => __( "The date the order was last modified, in the site's timezone.", 'woocommerce' ),
450
					'type'        => 'date-time',
451
					'context'     => array( 'view', 'edit' ),
452
					'readonly'    => true,
453
				),
454
				'date_modified_gmt'    => array(
455
					'description' => __( 'The date the order was last modified, as GMT.', 'woocommerce' ),
456
					'type'        => 'date-time',
457
					'context'     => array( 'view', 'edit' ),
458
					'readonly'    => true,
459
				),
460
				'discount_total'       => array(
461
					'description' => __( 'Total discount amount for the order.', 'woocommerce' ),
462
					'type'        => 'string',
463
					'context'     => array( 'view', 'edit' ),
464
					'readonly'    => true,
465
				),
466
				'discount_tax'         => array(
467
					'description' => __( 'Total discount tax amount for the order.', 'woocommerce' ),
468
					'type'        => 'string',
469
					'context'     => array( 'view', 'edit' ),
470
					'readonly'    => true,
471
				),
472
				'shipping_total'       => array(
473
					'description' => __( 'Total shipping amount for the order.', 'woocommerce' ),
474
					'type'        => 'string',
475
					'context'     => array( 'view', 'edit' ),
476
					'readonly'    => true,
477
				),
478
				'shipping_tax'         => array(
479
					'description' => __( 'Total shipping tax amount for the order.', 'woocommerce' ),
480
					'type'        => 'string',
481
					'context'     => array( 'view', 'edit' ),
482
					'readonly'    => true,
483
				),
484
				'cart_tax'             => array(
485
					'description' => __( 'Sum of line item taxes only.', 'woocommerce' ),
486
					'type'        => 'string',
487
					'context'     => array( 'view', 'edit' ),
488
					'readonly'    => true,
489
				),
490
				'total'                => array(
491
					'description' => __( 'Grand total.', 'woocommerce' ),
492
					'type'        => 'string',
493
					'context'     => array( 'view', 'edit' ),
494
					'readonly'    => true,
495
				),
496
				'total_tax'            => array(
497
					'description' => __( 'Sum of all taxes.', 'woocommerce' ),
498
					'type'        => 'string',
499
					'context'     => array( 'view', 'edit' ),
500
					'readonly'    => true,
501
				),
502
				'prices_include_tax'   => array(
503
					'description' => __( 'True the prices included tax during checkout.', 'woocommerce' ),
504
					'type'        => 'boolean',
505
					'context'     => array( 'view', 'edit' ),
506
					'readonly'    => true,
507
				),
508
				'customer_id'          => array(
509
					'description' => __( 'User ID who owns the order. 0 for guests.', 'woocommerce' ),
510
					'type'        => 'integer',
511
					'default'     => 0,
512
					'context'     => array( 'view', 'edit' ),
513
				),
514
				'customer_ip_address'  => array(
515
					'description' => __( "Customer's IP address.", 'woocommerce' ),
516
					'type'        => 'string',
517
					'context'     => array( 'view', 'edit' ),
518
					'readonly'    => true,
519
				),
520
				'customer_user_agent'  => array(
521
					'description' => __( 'User agent of the customer.', 'woocommerce' ),
522
					'type'        => 'string',
523
					'context'     => array( 'view', 'edit' ),
524
					'readonly'    => true,
525
				),
526
				'customer_note'        => array(
527
					'description' => __( 'Note left by customer during checkout.', 'woocommerce' ),
528
					'type'        => 'string',
529
					'context'     => array( 'view', 'edit' ),
530
				),
531
				'billing'              => array(
532
					'description' => __( 'Billing address.', 'woocommerce' ),
533
					'type'        => 'object',
534
					'context'     => array( 'view', 'edit' ),
535
					'properties'  => array(
536
						'first_name' => array(
537
							'description' => __( 'First name.', 'woocommerce' ),
538
							'type'        => 'string',
539
							'context'     => array( 'view', 'edit' ),
540
						),
541
						'last_name'  => array(
542
							'description' => __( 'Last name.', 'woocommerce' ),
543
							'type'        => 'string',
544
							'context'     => array( 'view', 'edit' ),
545
						),
546
						'company'    => array(
547
							'description' => __( 'Company name.', 'woocommerce' ),
548
							'type'        => 'string',
549
							'context'     => array( 'view', 'edit' ),
550
						),
551
						'address_1'  => array(
552
							'description' => __( 'Address line 1', 'woocommerce' ),
553
							'type'        => 'string',
554
							'context'     => array( 'view', 'edit' ),
555
						),
556
						'address_2'  => array(
557
							'description' => __( 'Address line 2', 'woocommerce' ),
558
							'type'        => 'string',
559
							'context'     => array( 'view', 'edit' ),
560
						),
561
						'city'       => array(
562
							'description' => __( 'City name.', 'woocommerce' ),
563
							'type'        => 'string',
564
							'context'     => array( 'view', 'edit' ),
565
						),
566
						'state'      => array(
567
							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
568
							'type'        => 'string',
569
							'context'     => array( 'view', 'edit' ),
570
						),
571
						'postcode'   => array(
572
							'description' => __( 'Postal code.', 'woocommerce' ),
573
							'type'        => 'string',
574
							'context'     => array( 'view', 'edit' ),
575
						),
576
						'country'    => array(
577
							'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ),
578
							'type'        => 'string',
579
							'context'     => array( 'view', 'edit' ),
580
						),
581
						'email'      => array(
582
							'description' => __( 'Email address.', 'woocommerce' ),
583
							'type'        => 'string',
584
							'format'      => 'email',
585
							'context'     => array( 'view', 'edit' ),
586
						),
587
						'phone'      => array(
588
							'description' => __( 'Phone number.', 'woocommerce' ),
589
							'type'        => 'string',
590
							'context'     => array( 'view', 'edit' ),
591
						),
592
					),
593
				),
594
				'shipping'             => array(
595
					'description' => __( 'Shipping address.', 'woocommerce' ),
596
					'type'        => 'object',
597
					'context'     => array( 'view', 'edit' ),
598
					'properties'  => array(
599
						'first_name' => array(
600
							'description' => __( 'First name.', 'woocommerce' ),
601
							'type'        => 'string',
602
							'context'     => array( 'view', 'edit' ),
603
						),
604
						'last_name'  => array(
605
							'description' => __( 'Last name.', 'woocommerce' ),
606
							'type'        => 'string',
607
							'context'     => array( 'view', 'edit' ),
608
						),
609
						'company'    => array(
610
							'description' => __( 'Company name.', 'woocommerce' ),
611
							'type'        => 'string',
612
							'context'     => array( 'view', 'edit' ),
613
						),
614
						'address_1'  => array(
615
							'description' => __( 'Address line 1', 'woocommerce' ),
616
							'type'        => 'string',
617
							'context'     => array( 'view', 'edit' ),
618
						),
619
						'address_2'  => array(
620
							'description' => __( 'Address line 2', 'woocommerce' ),
621
							'type'        => 'string',
622
							'context'     => array( 'view', 'edit' ),
623
						),
624
						'city'       => array(
625
							'description' => __( 'City name.', 'woocommerce' ),
626
							'type'        => 'string',
627
							'context'     => array( 'view', 'edit' ),
628
						),
629
						'state'      => array(
630
							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
631
							'type'        => 'string',
632
							'context'     => array( 'view', 'edit' ),
633
						),
634
						'postcode'   => array(
635
							'description' => __( 'Postal code.', 'woocommerce' ),
636
							'type'        => 'string',
637
							'context'     => array( 'view', 'edit' ),
638
						),
639
						'country'    => array(
640
							'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ),
641
							'type'        => 'string',
642
							'context'     => array( 'view', 'edit' ),
643
						),
644
					),
645
				),
646
				'payment_method'       => array(
647
					'description' => __( 'Payment method ID.', 'woocommerce' ),
648
					'type'        => 'string',
649
					'context'     => array( 'view', 'edit' ),
650
				),
651
				'payment_method_title' => array(
652
					'description' => __( 'Payment method title.', 'woocommerce' ),
653
					'type'        => 'string',
654
					'context'     => array( 'view', 'edit' ),
655
					'arg_options' => array(
656
						'sanitize_callback' => 'sanitize_text_field',
657
					),
658
				),
659
				'transaction_id'       => array(
660
					'description' => __( 'Unique transaction ID.', 'woocommerce' ),
661
					'type'        => 'string',
662
					'context'     => array( 'view', 'edit' ),
663
				),
664
				'date_paid'            => array(
665
					'description' => __( "The date the order was paid, in the site's timezone.", 'woocommerce' ),
666
					'type'        => 'date-time',
667
					'context'     => array( 'view', 'edit' ),
668
					'readonly'    => true,
669
				),
670
				'date_paid_gmt'        => array(
671
					'description' => __( 'The date the order was paid, as GMT.', 'woocommerce' ),
672
					'type'        => 'date-time',
673
					'context'     => array( 'view', 'edit' ),
674
					'readonly'    => true,
675
				),
676
				'date_completed'       => array(
677
					'description' => __( "The date the order was completed, in the site's timezone.", 'woocommerce' ),
678
					'type'        => 'date-time',
679
					'context'     => array( 'view', 'edit' ),
680
					'readonly'    => true,
681
				),
682
				'date_completed_gmt'   => array(
683
					'description' => __( 'The date the order was completed, as GMT.', 'woocommerce' ),
684
					'type'        => 'date-time',
685
					'context'     => array( 'view', 'edit' ),
686
					'readonly'    => true,
687
				),
688
				'cart_hash'            => array(
689
					'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ),
690
					'type'        => 'string',
691
					'context'     => array( 'view', 'edit' ),
692
					'readonly'    => true,
693
				),
694
				'meta_data'            => array(
695
					'description' => __( 'Meta data.', 'woocommerce' ),
696
					'type'        => 'array',
697
					'context'     => array( 'view', 'edit' ),
698
					'items'       => array(
699
						'type'       => 'object',
700
						'properties' => array(
701
							'id'    => array(
702
								'description' => __( 'Meta ID.', 'woocommerce' ),
703
								'type'        => 'integer',
704
								'context'     => array( 'view', 'edit' ),
705
								'readonly'    => true,
706
							),
707
							'key'   => array(
708
								'description' => __( 'Meta key.', 'woocommerce' ),
709
								'type'        => 'string',
710
								'context'     => array( 'view', 'edit' ),
711
							),
712
							'value' => array(
713
								'description' => __( 'Meta value.', 'woocommerce' ),
714
								'type'        => 'mixed',
715
								'context'     => array( 'view', 'edit' ),
716
							),
717
						),
718
					),
719
				),
720
				'line_items'           => array(
721
					'description' => __( 'Line items data.', 'woocommerce' ),
722
					'type'        => 'array',
723
					'context'     => array( 'view', 'edit' ),
724
					'items'       => array(
725
						'type'       => 'object',
726
						'properties' => array(
727
							'id'           => array(
728
								'description' => __( 'Item ID.', 'woocommerce' ),
729
								'type'        => 'integer',
730
								'context'     => array( 'view', 'edit' ),
731
								'readonly'    => true,
732
							),
733
							'name'         => array(
734
								'description' => __( 'Product name.', 'woocommerce' ),
735
								'type'        => 'mixed',
736
								'context'     => array( 'view', 'edit' ),
737
							),
738
							'product_id'   => array(
739
								'description' => __( 'Product ID.', 'woocommerce' ),
740
								'type'        => 'mixed',
741
								'context'     => array( 'view', 'edit' ),
742
							),
743
							'variation_id' => array(
744
								'description' => __( 'Variation ID, if applicable.', 'woocommerce' ),
745
								'type'        => 'integer',
746
								'context'     => array( 'view', 'edit' ),
747
							),
748
							'quantity'     => array(
749
								'description' => __( 'Quantity ordered.', 'woocommerce' ),
750
								'type'        => 'integer',
751
								'context'     => array( 'view', 'edit' ),
752
							),
753
							'tax_class'    => array(
754
								'description' => __( 'Tax class of product.', 'woocommerce' ),
755
								'type'        => 'string',
756
								'context'     => array( 'view', 'edit' ),
757
							),
758
							'subtotal'     => array(
759
								'description' => __( 'Line subtotal (before discounts).', 'woocommerce' ),
760
								'type'        => 'string',
761
								'context'     => array( 'view', 'edit' ),
762
							),
763
							'subtotal_tax' => array(
764
								'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce' ),
765
								'type'        => 'string',
766
								'context'     => array( 'view', 'edit' ),
767
								'readonly'    => true,
768
							),
769
							'total'        => array(
770
								'description' => __( 'Line total (after discounts).', 'woocommerce' ),
771
								'type'        => 'string',
772
								'context'     => array( 'view', 'edit' ),
773
							),
774
							'total_tax'    => array(
775
								'description' => __( 'Line total tax (after discounts).', 'woocommerce' ),
776
								'type'        => 'string',
777
								'context'     => array( 'view', 'edit' ),
778
								'readonly'    => true,
779
							),
780
							'taxes'        => array(
781
								'description' => __( 'Line taxes.', 'woocommerce' ),
782
								'type'        => 'array',
783
								'context'     => array( 'view', 'edit' ),
784
								'readonly'    => true,
785
								'items'       => array(
786
									'type'       => 'object',
787
									'properties' => array(
788
										'id'       => array(
789
											'description' => __( 'Tax rate ID.', 'woocommerce' ),
790
											'type'        => 'integer',
791
											'context'     => array( 'view', 'edit' ),
792
										),
793
										'total'    => array(
794
											'description' => __( 'Tax total.', 'woocommerce' ),
795
											'type'        => 'string',
796
											'context'     => array( 'view', 'edit' ),
797
										),
798
										'subtotal' => array(
799
											'description' => __( 'Tax subtotal.', 'woocommerce' ),
800
											'type'        => 'string',
801
											'context'     => array( 'view', 'edit' ),
802
										),
803
									),
804
								),
805
							),
806
							'meta_data'    => array(
807
								'description' => __( 'Meta data.', 'woocommerce' ),
808
								'type'        => 'array',
809
								'context'     => array( 'view', 'edit' ),
810
								'items'       => array(
811
									'type'       => 'object',
812
									'properties' => array(
813
										'id'    => array(
814
											'description' => __( 'Meta ID.', 'woocommerce' ),
815
											'type'        => 'integer',
816
											'context'     => array( 'view', 'edit' ),
817
											'readonly'    => true,
818
										),
819
										'key'   => array(
820
											'description' => __( 'Meta key.', 'woocommerce' ),
821
											'type'        => 'string',
822
											'context'     => array( 'view', 'edit' ),
823
										),
824
										'value' => array(
825
											'description' => __( 'Meta value.', 'woocommerce' ),
826
											'type'        => 'mixed',
827
											'context'     => array( 'view', 'edit' ),
828
										),
829
									),
830
								),
831
							),
832
							'sku'          => array(
833
								'description' => __( 'Product SKU.', 'woocommerce' ),
834
								'type'        => 'string',
835
								'context'     => array( 'view', 'edit' ),
836
								'readonly'    => true,
837
							),
838
							'price'        => array(
839
								'description' => __( 'Product price.', 'woocommerce' ),
840
								'type'        => 'number',
841
								'context'     => array( 'view', 'edit' ),
842
								'readonly'    => true,
843
							),
844
						),
845
					),
846
				),
847
				'tax_lines'            => array(
848
					'description' => __( 'Tax lines data.', 'woocommerce' ),
849
					'type'        => 'array',
850
					'context'     => array( 'view', 'edit' ),
851
					'readonly'    => true,
852
					'items'       => array(
853
						'type'       => 'object',
854
						'properties' => array(
855
							'id'                 => array(
856
								'description' => __( 'Item ID.', 'woocommerce' ),
857
								'type'        => 'integer',
858
								'context'     => array( 'view', 'edit' ),
859
								'readonly'    => true,
860
							),
861
							'rate_code'          => array(
862
								'description' => __( 'Tax rate code.', 'woocommerce' ),
863
								'type'        => 'string',
864
								'context'     => array( 'view', 'edit' ),
865
								'readonly'    => true,
866
							),
867
							'rate_id'            => array(
868
								'description' => __( 'Tax rate ID.', 'woocommerce' ),
869
								'type'        => 'string',
870
								'context'     => array( 'view', 'edit' ),
871
								'readonly'    => true,
872
							),
873
							'label'              => array(
874
								'description' => __( 'Tax rate label.', 'woocommerce' ),
875
								'type'        => 'string',
876
								'context'     => array( 'view', 'edit' ),
877
								'readonly'    => true,
878
							),
879
							'compound'           => array(
880
								'description' => __( 'Show if is a compound tax rate.', 'woocommerce' ),
881
								'type'        => 'boolean',
882
								'context'     => array( 'view', 'edit' ),
883
								'readonly'    => true,
884
							),
885
							'tax_total'          => array(
886
								'description' => __( 'Tax total (not including shipping taxes).', 'woocommerce' ),
887
								'type'        => 'string',
888
								'context'     => array( 'view', 'edit' ),
889
								'readonly'    => true,
890
							),
891
							'shipping_tax_total' => array(
892
								'description' => __( 'Shipping tax total.', 'woocommerce' ),
893
								'type'        => 'string',
894
								'context'     => array( 'view', 'edit' ),
895
								'readonly'    => true,
896
							),
897
							'meta_data'          => array(
898
								'description' => __( 'Meta data.', 'woocommerce' ),
899
								'type'        => 'array',
900
								'context'     => array( 'view', 'edit' ),
901
								'items'       => array(
902
									'type'       => 'object',
903
									'properties' => array(
904
										'id'    => array(
905
											'description' => __( 'Meta ID.', 'woocommerce' ),
906
											'type'        => 'integer',
907
											'context'     => array( 'view', 'edit' ),
908
											'readonly'    => true,
909
										),
910
										'key'   => array(
911
											'description' => __( 'Meta key.', 'woocommerce' ),
912
											'type'        => 'string',
913
											'context'     => array( 'view', 'edit' ),
914
										),
915
										'value' => array(
916
											'description' => __( 'Meta value.', 'woocommerce' ),
917
											'type'        => 'mixed',
918
											'context'     => array( 'view', 'edit' ),
919
										),
920
									),
921
								),
922
							),
923
						),
924
					),
925
				),
926
				'shipping_lines'       => array(
927
					'description' => __( 'Shipping lines data.', 'woocommerce' ),
928
					'type'        => 'array',
929
					'context'     => array( 'view', 'edit' ),
930
					'items'       => array(
931
						'type'       => 'object',
932
						'properties' => array(
933
							'id'           => array(
934
								'description' => __( 'Item ID.', 'woocommerce' ),
935
								'type'        => 'integer',
936
								'context'     => array( 'view', 'edit' ),
937
								'readonly'    => true,
938
							),
939
							'method_title' => array(
940
								'description' => __( 'Shipping method name.', 'woocommerce' ),
941
								'type'        => 'mixed',
942
								'context'     => array( 'view', 'edit' ),
943
							),
944
							'method_id'    => array(
945
								'description' => __( 'Shipping method ID.', 'woocommerce' ),
946
								'type'        => 'mixed',
947
								'context'     => array( 'view', 'edit' ),
948
							),
949
							'instance_id'  => array(
950
								'description' => __( 'Shipping instance ID.', 'woocommerce' ),
951
								'type'        => 'string',
952
								'context'     => array( 'view', 'edit' ),
953
							),
954
							'total'        => array(
955
								'description' => __( 'Line total (after discounts).', 'woocommerce' ),
956
								'type'        => 'string',
957
								'context'     => array( 'view', 'edit' ),
958
							),
959
							'total_tax'    => array(
960
								'description' => __( 'Line total tax (after discounts).', 'woocommerce' ),
961
								'type'        => 'string',
962
								'context'     => array( 'view', 'edit' ),
963
								'readonly'    => true,
964
							),
965
							'taxes'        => array(
966
								'description' => __( 'Line taxes.', 'woocommerce' ),
967
								'type'        => 'array',
968
								'context'     => array( 'view', 'edit' ),
969
								'readonly'    => true,
970
								'items'       => array(
971
									'type'       => 'object',
972
									'properties' => array(
973
										'id'    => array(
974
											'description' => __( 'Tax rate ID.', 'woocommerce' ),
975
											'type'        => 'integer',
976
											'context'     => array( 'view', 'edit' ),
977
											'readonly'    => true,
978
										),
979
										'total' => array(
980
											'description' => __( 'Tax total.', 'woocommerce' ),
981
											'type'        => 'string',
982
											'context'     => array( 'view', 'edit' ),
983
											'readonly'    => true,
984
										),
985
									),
986
								),
987
							),
988
							'meta_data'    => array(
989
								'description' => __( 'Meta data.', 'woocommerce' ),
990
								'type'        => 'array',
991
								'context'     => array( 'view', 'edit' ),
992
								'items'       => array(
993
									'type'       => 'object',
994
									'properties' => array(
995
										'id'    => array(
996
											'description' => __( 'Meta ID.', 'woocommerce' ),
997
											'type'        => 'integer',
998
											'context'     => array( 'view', 'edit' ),
999
											'readonly'    => true,
1000
										),
1001
										'key'   => array(
1002
											'description' => __( 'Meta key.', 'woocommerce' ),
1003
											'type'        => 'string',
1004
											'context'     => array( 'view', 'edit' ),
1005
										),
1006
										'value' => array(
1007
											'description' => __( 'Meta value.', 'woocommerce' ),
1008
											'type'        => 'mixed',
1009
											'context'     => array( 'view', 'edit' ),
1010
										),
1011
									),
1012
								),
1013
							),
1014
						),
1015
					),
1016
				),
1017
				'fee_lines'            => array(
1018
					'description' => __( 'Fee lines data.', 'woocommerce' ),
1019
					'type'        => 'array',
1020
					'context'     => array( 'view', 'edit' ),
1021
					'items'       => array(
1022
						'type'       => 'object',
1023
						'properties' => array(
1024
							'id'         => array(
1025
								'description' => __( 'Item ID.', 'woocommerce' ),
1026
								'type'        => 'integer',
1027
								'context'     => array( 'view', 'edit' ),
1028
								'readonly'    => true,
1029
							),
1030
							'name'       => array(
1031
								'description' => __( 'Fee name.', 'woocommerce' ),
1032
								'type'        => 'mixed',
1033
								'context'     => array( 'view', 'edit' ),
1034
							),
1035
							'tax_class'  => array(
1036
								'description' => __( 'Tax class of fee.', 'woocommerce' ),
1037
								'type'        => 'string',
1038
								'context'     => array( 'view', 'edit' ),
1039
							),
1040
							'tax_status' => array(
1041
								'description' => __( 'Tax status of fee.', 'woocommerce' ),
1042
								'type'        => 'string',
1043
								'context'     => array( 'view', 'edit' ),
1044
								'enum'        => array( 'taxable', 'none' ),
1045
							),
1046
							'total'      => array(
1047
								'description' => __( 'Line total (after discounts).', 'woocommerce' ),
1048
								'type'        => 'string',
1049
								'context'     => array( 'view', 'edit' ),
1050
							),
1051
							'total_tax'  => array(
1052
								'description' => __( 'Line total tax (after discounts).', 'woocommerce' ),
1053
								'type'        => 'string',
1054
								'context'     => array( 'view', 'edit' ),
1055
								'readonly'    => true,
1056
							),
1057
							'taxes'      => array(
1058
								'description' => __( 'Line taxes.', 'woocommerce' ),
1059
								'type'        => 'array',
1060
								'context'     => array( 'view', 'edit' ),
1061
								'readonly'    => true,
1062
								'items'       => array(
1063
									'type'       => 'object',
1064
									'properties' => array(
1065
										'id'       => array(
1066
											'description' => __( 'Tax rate ID.', 'woocommerce' ),
1067
											'type'        => 'integer',
1068
											'context'     => array( 'view', 'edit' ),
1069
											'readonly'    => true,
1070
										),
1071
										'total'    => array(
1072
											'description' => __( 'Tax total.', 'woocommerce' ),
1073
											'type'        => 'string',
1074
											'context'     => array( 'view', 'edit' ),
1075
											'readonly'    => true,
1076
										),
1077
										'subtotal' => array(
1078
											'description' => __( 'Tax subtotal.', 'woocommerce' ),
1079
											'type'        => 'string',
1080
											'context'     => array( 'view', 'edit' ),
1081
											'readonly'    => true,
1082
										),
1083
									),
1084
								),
1085
							),
1086
							'meta_data'  => array(
1087
								'description' => __( 'Meta data.', 'woocommerce' ),
1088
								'type'        => 'array',
1089
								'context'     => array( 'view', 'edit' ),
1090
								'items'       => array(
1091
									'type'       => 'object',
1092
									'properties' => array(
1093
										'id'    => array(
1094
											'description' => __( 'Meta ID.', 'woocommerce' ),
1095
											'type'        => 'integer',
1096
											'context'     => array( 'view', 'edit' ),
1097
											'readonly'    => true,
1098
										),
1099
										'key'   => array(
1100
											'description' => __( 'Meta key.', 'woocommerce' ),
1101
											'type'        => 'string',
1102
											'context'     => array( 'view', 'edit' ),
1103
										),
1104
										'value' => array(
1105
											'description' => __( 'Meta value.', 'woocommerce' ),
1106
											'type'        => 'mixed',
1107
											'context'     => array( 'view', 'edit' ),
1108
										),
1109
									),
1110
								),
1111
							),
1112
						),
1113
					),
1114
				),
1115
				'coupon_lines'         => array(
1116
					'description' => __( 'Coupons line data.', 'woocommerce' ),
1117
					'type'        => 'array',
1118
					'context'     => array( 'view', 'edit' ),
1119
					'items'       => array(
1120
						'type'       => 'object',
1121
						'properties' => array(
1122
							'id'           => array(
1123
								'description' => __( 'Item ID.', 'woocommerce' ),
1124
								'type'        => 'integer',
1125
								'context'     => array( 'view', 'edit' ),
1126
								'readonly'    => true,
1127
							),
1128
							'code'         => array(
1129
								'description' => __( 'Coupon code.', 'woocommerce' ),
1130
								'type'        => 'mixed',
1131
								'context'     => array( 'view', 'edit' ),
1132
							),
1133
							'discount'     => array(
1134
								'description' => __( 'Discount total.', 'woocommerce' ),
1135
								'type'        => 'string',
1136
								'context'     => array( 'view', 'edit' ),
1137
								'readonly'    => true,
1138
							),
1139
							'discount_tax' => array(
1140
								'description' => __( 'Discount total tax.', 'woocommerce' ),
1141
								'type'        => 'string',
1142
								'context'     => array( 'view', 'edit' ),
1143
								'readonly'    => true,
1144
							),
1145
							'meta_data'    => array(
1146
								'description' => __( 'Meta data.', 'woocommerce' ),
1147
								'type'        => 'array',
1148
								'context'     => array( 'view', 'edit' ),
1149
								'items'       => array(
1150
									'type'       => 'object',
1151
									'properties' => array(
1152
										'id'    => array(
1153
											'description' => __( 'Meta ID.', 'woocommerce' ),
1154
											'type'        => 'integer',
1155
											'context'     => array( 'view', 'edit' ),
1156
											'readonly'    => true,
1157
										),
1158
										'key'   => array(
1159
											'description' => __( 'Meta key.', 'woocommerce' ),
1160
											'type'        => 'string',
1161
											'context'     => array( 'view', 'edit' ),
1162
										),
1163
										'value' => array(
1164
											'description' => __( 'Meta value.', 'woocommerce' ),
1165
											'type'        => 'mixed',
1166
											'context'     => array( 'view', 'edit' ),
1167
										),
1168
									),
1169
								),
1170
							),
1171
						),
1172
					),
1173
				),
1174
				'refunds'              => array(
1175
					'description' => __( 'List of refunds.', 'woocommerce' ),
1176
					'type'        => 'array',
1177
					'context'     => array( 'view', 'edit' ),
1178
					'readonly'    => true,
1179
					'items'       => array(
1180
						'type'       => 'object',
1181
						'properties' => array(
1182
							'id'     => array(
1183
								'description' => __( 'Refund ID.', 'woocommerce' ),
1184
								'type'        => 'integer',
1185
								'context'     => array( 'view', 'edit' ),
1186
								'readonly'    => true,
1187
							),
1188
							'reason' => array(
1189
								'description' => __( 'Refund reason.', 'woocommerce' ),
1190
								'type'        => 'string',
1191
								'context'     => array( 'view', 'edit' ),
1192
								'readonly'    => true,
1193
							),
1194
							'total'  => array(
1195
								'description' => __( 'Refund total.', 'woocommerce' ),
1196
								'type'        => 'string',
1197
								'context'     => array( 'view', 'edit' ),
1198
								'readonly'    => true,
1199
							),
1200
						),
1201
					),
1202
				),
1203
				'set_paid'             => array(
1204
					'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce' ),
1205
					'type'        => 'boolean',
1206
					'default'     => false,
1207
					'context'     => array( 'edit' ),
1208
				),
1209
			),
1210
		);
1211
1212
		return $this->add_additional_fields_schema( $schema );
1213
	}
1214
1215
	/**
1216
	 * Get the query params for collections.
1217
	 *
1218
	 * @return array
1219
	 */
1220
	public function get_collection_params() {
1221
		$params = parent::get_collection_params();
1222
1223
		$params['status']   = array(
1224
			'default'           => 'any',
1225
			'description'       => __( 'Limit result set to orders which have specific statuses.', 'woocommerce' ),
1226
			'type'              => 'array',
1227
			'items'             => array(
1228
				'type' => 'string',
1229
				'enum' => array_merge( array( 'any', 'trash' ), $this->get_order_statuses() ),
1230
			),
1231
			'validate_callback' => 'rest_validate_request_arg',
1232
		);
1233
		$params['customer'] = array(
1234
			'description'       => __( 'Limit result set to orders assigned a specific customer.', 'woocommerce' ),
1235
			'type'              => 'integer',
1236
			'sanitize_callback' => 'absint',
1237
			'validate_callback' => 'rest_validate_request_arg',
1238
		);
1239
		$params['product']  = array(
1240
			'description'       => __( 'Limit result set to orders assigned a specific product.', 'woocommerce' ),
1241
			'type'              => 'integer',
1242
			'sanitize_callback' => 'absint',
1243
			'validate_callback' => 'rest_validate_request_arg',
1244
		);
1245
		$params['dp']       = array(
1246
			'default'           => wc_get_price_decimals(),
1247
			'description'       => __( 'Number of decimal points to use in each resource.', 'woocommerce' ),
1248
			'type'              => 'integer',
1249
			'sanitize_callback' => 'absint',
1250
			'validate_callback' => 'rest_validate_request_arg',
1251
		);
1252
		// This needs to remain a string to support extensions that filter Order Number.
1253
		$params['number'] = array(
1254
			'description'       => __( 'Limit result set to orders matching part of an order number.', 'woocommerce' ),
1255
			'type'              => 'string',
1256
			'validate_callback' => 'rest_validate_request_arg',
1257
		);
1258
1259
		return $params;
1260
	}
1261
}
1262