1 | <?php |
||||||||||
2 | /** |
||||||||||
3 | * REST API Orders controller |
||||||||||
4 | * |
||||||||||
5 | * Handles requests to the /orders endpoint. |
||||||||||
6 | * |
||||||||||
7 | * @package Automattic/WooCommerce/RestApi |
||||||||||
8 | */ |
||||||||||
9 | |||||||||||
10 | namespace Automattic\WooCommerce\RestApi\Controllers\Version4; |
||||||||||
11 | |||||||||||
12 | defined( 'ABSPATH' ) || exit; |
||||||||||
13 | |||||||||||
14 | use Automattic\WooCommerce\RestApi\Controllers\Version4\Requests\OrderRequest; |
||||||||||
15 | use Automattic\WooCommerce\RestApi\Controllers\Version4\Responses\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 | * Get object. Return false if object is not of required type. |
||||||||||
45 | * |
||||||||||
46 | * @since 3.0.0 |
||||||||||
47 | * @param int $id Object ID. |
||||||||||
48 | * @return \WC_Data|bool |
||||||||||
49 | */ |
||||||||||
50 | protected function get_object( $id ) { |
||||||||||
51 | $order = wc_get_order( $id ); |
||||||||||
52 | // In case id is a refund's id (or it's not an order at all), don't expose it via /orders/ path. |
||||||||||
53 | if ( ! $order || 'shop_order_refund' === $order->get_type() ) { |
||||||||||
54 | return false; |
||||||||||
55 | } |
||||||||||
56 | |||||||||||
57 | return $order; |
||||||||||
58 | } |
||||||||||
59 | |||||||||||
60 | /** |
||||||||||
61 | * Get data for this object in the format of this endpoint's schema. |
||||||||||
62 | * |
||||||||||
63 | * @param \WC_Order $object Object to prepare. |
||||||||||
64 | * @param \WP_REST_Request $request Request object. |
||||||||||
65 | * @return array Array of data in the correct format. |
||||||||||
66 | */ |
||||||||||
67 | protected function get_data_for_response( $object, $request ) { |
||||||||||
68 | $formatter = new OrderResponse(); |
||||||||||
69 | |||||||||||
70 | if ( ! is_null( $request['dp'] ) ) { |
||||||||||
71 | $formatter->set_dp( $request['dp'] ); |
||||||||||
72 | } |
||||||||||
73 | |||||||||||
74 | return $formatter->prepare_response( $object, $this->get_request_context( $request ) ); |
||||||||||
75 | } |
||||||||||
76 | |||||||||||
77 | /** |
||||||||||
78 | * Prepare links for the request. |
||||||||||
79 | * |
||||||||||
80 | * @param mixed $item Object to prepare. |
||||||||||
81 | * @param \WP_REST_Request $request Request object. |
||||||||||
82 | * @return array |
||||||||||
83 | */ |
||||||||||
84 | protected function prepare_links( $item, $request ) { |
||||||||||
85 | $links = array( |
||||||||||
86 | 'self' => array( |
||||||||||
87 | 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $item->get_id() ) ), |
||||||||||
88 | ), |
||||||||||
89 | 'collection' => array( |
||||||||||
90 | 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
||||||||||
91 | ), |
||||||||||
92 | ); |
||||||||||
93 | |||||||||||
94 | if ( 0 !== (int) $item->get_customer_id() ) { |
||||||||||
95 | $links['customer'] = array( |
||||||||||
96 | 'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $item->get_customer_id() ) ), |
||||||||||
97 | ); |
||||||||||
98 | } |
||||||||||
99 | |||||||||||
100 | if ( 0 !== (int) $item->get_parent_id() ) { |
||||||||||
101 | $links['up'] = array( |
||||||||||
102 | 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $item->get_parent_id() ) ), |
||||||||||
103 | ); |
||||||||||
104 | } |
||||||||||
105 | |||||||||||
106 | return $links; |
||||||||||
107 | } |
||||||||||
108 | |||||||||||
109 | /** |
||||||||||
110 | * Prepare objects query. |
||||||||||
111 | * |
||||||||||
112 | * @since 3.0.0 |
||||||||||
113 | * @param \WP_REST_Request $request Full details about the request. |
||||||||||
114 | * @return array |
||||||||||
115 | */ |
||||||||||
116 | protected function prepare_objects_query( $request ) { |
||||||||||
117 | global $wpdb; |
||||||||||
118 | |||||||||||
119 | // This is needed to get around an array to string notice in \WC_REST_Orders_V2_Controller::prepare_objects_query. |
||||||||||
120 | $statuses = $request['status']; |
||||||||||
121 | unset( $request['status'] ); |
||||||||||
122 | $args = parent::prepare_objects_query( $request ); |
||||||||||
123 | |||||||||||
124 | $args['post_status'] = array(); |
||||||||||
125 | foreach ( $statuses as $status ) { |
||||||||||
126 | if ( in_array( $status, $this->get_order_statuses(), true ) ) { |
||||||||||
127 | $args['post_status'][] = 'wc-' . $status; |
||||||||||
128 | } elseif ( 'any' === $status ) { |
||||||||||
129 | // Set status to "any" and short-circuit out. |
||||||||||
130 | $args['post_status'] = 'any'; |
||||||||||
131 | break; |
||||||||||
132 | } else { |
||||||||||
133 | $args['post_status'][] = $status; |
||||||||||
134 | } |
||||||||||
135 | } |
||||||||||
136 | |||||||||||
137 | // Put the statuses back for further processing (next/prev links, etc). |
||||||||||
138 | $request['status'] = $statuses; |
||||||||||
139 | |||||||||||
140 | // Customer. |
||||||||||
141 | if ( isset( $request['customer'] ) ) { |
||||||||||
142 | if ( ! empty( $args['meta_query'] ) ) { |
||||||||||
143 | $args['meta_query'] = array(); // WPCS: slow query ok. |
||||||||||
144 | } |
||||||||||
145 | |||||||||||
146 | $args['meta_query'][] = array( |
||||||||||
147 | 'key' => '_customer_user', |
||||||||||
148 | 'value' => $request['customer'], |
||||||||||
149 | 'type' => 'NUMERIC', |
||||||||||
150 | ); |
||||||||||
151 | } |
||||||||||
152 | |||||||||||
153 | // Search by product. |
||||||||||
154 | if ( ! empty( $request['product'] ) ) { |
||||||||||
155 | $order_ids = $wpdb->get_col( |
||||||||||
156 | $wpdb->prepare( |
||||||||||
157 | "SELECT order_id |
||||||||||
158 | FROM {$wpdb->prefix}woocommerce_order_items |
||||||||||
159 | WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key = '_product_id' AND meta_value = %d ) |
||||||||||
160 | AND order_item_type = 'line_item'", |
||||||||||
161 | $request['product'] |
||||||||||
162 | ) |
||||||||||
163 | ); |
||||||||||
164 | |||||||||||
165 | // Force WP_Query return empty if don't found any order. |
||||||||||
166 | $order_ids = ! empty( $order_ids ) ? $order_ids : array( 0 ); |
||||||||||
167 | |||||||||||
168 | $args['post__in'] = $order_ids; |
||||||||||
169 | } |
||||||||||
170 | |||||||||||
171 | // Search. |
||||||||||
172 | if ( ! empty( $args['s'] ) ) { |
||||||||||
173 | $order_ids = wc_order_search( $args['s'] ); |
||||||||||
174 | |||||||||||
175 | if ( ! empty( $order_ids ) ) { |
||||||||||
176 | unset( $args['s'] ); |
||||||||||
177 | $args['post__in'] = array_merge( $order_ids, array( 0 ) ); |
||||||||||
178 | } |
||||||||||
179 | } |
||||||||||
180 | |||||||||||
181 | // Search by partial order number. |
||||||||||
182 | if ( ! empty( $request['number'] ) ) { |
||||||||||
183 | $partial_number = trim( $request['number'] ); |
||||||||||
184 | $limit = intval( $args['posts_per_page'] ); |
||||||||||
185 | $order_ids = $wpdb->get_col( |
||||||||||
186 | $wpdb->prepare( |
||||||||||
187 | "SELECT ID |
||||||||||
188 | FROM {$wpdb->prefix}posts |
||||||||||
189 | WHERE post_type = 'shop_order' |
||||||||||
190 | AND ID LIKE %s |
||||||||||
191 | LIMIT %d", |
||||||||||
192 | $wpdb->esc_like( absint( $partial_number ) ) . '%', |
||||||||||
193 | $limit |
||||||||||
194 | ) |
||||||||||
195 | ); |
||||||||||
196 | |||||||||||
197 | // Force \WP_Query return empty if don't found any order. |
||||||||||
198 | $order_ids = empty( $order_ids ) ? array( 0 ) : $order_ids; |
||||||||||
199 | $args['post__in'] = $order_ids; |
||||||||||
200 | } |
||||||||||
201 | |||||||||||
202 | return $args; |
||||||||||
203 | } |
||||||||||
204 | |||||||||||
205 | /** |
||||||||||
206 | * Prepare a single order for create or update. |
||||||||||
207 | * |
||||||||||
208 | * @throws \WC_REST_Exception When fails to set any item. |
||||||||||
209 | * @param \WP_REST_Request $request Request object. |
||||||||||
210 | * @param bool $creating If is creating a new object. |
||||||||||
211 | * @return \WP_Error|\WC_Data |
||||||||||
212 | */ |
||||||||||
213 | protected function prepare_object_for_database( $request, $creating = false ) { |
||||||||||
214 | try { |
||||||||||
215 | $order_request = new OrderRequest( $request ); |
||||||||||
216 | $order = $order_request->prepare_object(); |
||||||||||
217 | } catch ( \WC_REST_Exception $e ) { |
||||||||||
218 | return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
||||||||||
219 | } |
||||||||||
220 | |||||||||||
221 | /** |
||||||||||
222 | * Filters an object before it is inserted via the REST API. |
||||||||||
223 | * |
||||||||||
224 | * The dynamic portion of the hook name, `$this->post_type`, |
||||||||||
225 | * refers to the object type slug. |
||||||||||
226 | * |
||||||||||
227 | * @param \WC_Data $order Object object. |
||||||||||
228 | * @param \WP_REST_Request $request Request object. |
||||||||||
229 | * @param bool $creating If is creating a new object. |
||||||||||
230 | */ |
||||||||||
231 | return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating ); |
||||||||||
232 | } |
||||||||||
233 | |||||||||||
234 | /** |
||||||||||
235 | * Save an object data. |
||||||||||
236 | * |
||||||||||
237 | * @param \WP_REST_Request $request Full details about the request. |
||||||||||
238 | * @param bool $creating If is creating a new object. |
||||||||||
239 | * @return \WC_Data|\WP_Error |
||||||||||
240 | * @throws \WC_REST_Exception But all errors are validated before returning any data. |
||||||||||
241 | */ |
||||||||||
242 | protected function save_object( $request, $creating = false ) { |
||||||||||
243 | try { |
||||||||||
244 | $object = $this->prepare_object_for_database( $request, $creating ); |
||||||||||
245 | |||||||||||
246 | if ( is_wp_error( $object ) ) { |
||||||||||
247 | return $object; |
||||||||||
248 | } |
||||||||||
249 | |||||||||||
250 | // Make sure gateways are loaded so hooks from gateways fire on save/create. |
||||||||||
251 | WC()->payment_gateways(); |
||||||||||
252 | |||||||||||
253 | if ( $creating ) { |
||||||||||
254 | $object->set_created_via( 'rest-api' ); |
||||||||||
0 ignored issues
–
show
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
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. ![]() |
|||||||||||
255 | $object->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) ); |
||||||||||
0 ignored issues
–
show
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
![]() 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
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. ![]() |
|||||||||||
256 | $object->calculate_totals(); |
||||||||||
0 ignored issues
–
show
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
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. ![]() 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
![]() |
|||||||||||
257 | } else { |
||||||||||
258 | // If items have changed, recalculate order totals. |
||||||||||
259 | if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) { |
||||||||||
260 | $object->calculate_totals( true ); |
||||||||||
261 | } |
||||||||||
262 | } |
||||||||||
263 | |||||||||||
264 | $object->save(); |
||||||||||
0 ignored issues
–
show
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
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. ![]() |
|||||||||||
265 | |||||||||||
266 | // Actions for after the order is saved. |
||||||||||
267 | if ( true === $request['set_paid'] && ( $creating || $object->needs_payment() ) ) { |
||||||||||
0 ignored issues
–
show
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
![]() 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
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. ![]() |
|||||||||||
268 | $object->payment_complete(); |
||||||||||
0 ignored issues
–
show
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
![]() 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
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. ![]() |
|||||||||||
269 | } |
||||||||||
270 | |||||||||||
271 | return $this->get_object( $object->get_id() ); |
||||||||||
0 ignored issues
–
show
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
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. ![]() |
|||||||||||
272 | } catch ( \WC_Data_Exception $e ) { |
||||||||||
273 | return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
||||||||||
274 | } catch ( \WC_REST_Exception $e ) { |
||||||||||
275 | return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
||||||||||
276 | } |
||||||||||
277 | } |
||||||||||
278 | |||||||||||
279 | /** |
||||||||||
280 | * Get order statuses without prefixes. |
||||||||||
281 | * |
||||||||||
282 | * @return array |
||||||||||
283 | */ |
||||||||||
284 | protected function get_order_statuses() { |
||||||||||
285 | $order_statuses = array(); |
||||||||||
286 | |||||||||||
287 | foreach ( array_keys( wc_get_order_statuses() ) as $status ) { |
||||||||||
288 | $order_statuses[] = str_replace( 'wc-', '', $status ); |
||||||||||
289 | } |
||||||||||
290 | |||||||||||
291 | return $order_statuses; |
||||||||||
292 | } |
||||||||||
293 | |||||||||||
294 | /** |
||||||||||
295 | * Get the Order's schema, conforming to JSON Schema. |
||||||||||
296 | * |
||||||||||
297 | * @return array |
||||||||||
298 | */ |
||||||||||
299 | public function get_item_schema() { |
||||||||||
300 | $schema = array( |
||||||||||
301 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
||||||||||
302 | 'title' => $this->post_type, |
||||||||||
303 | 'type' => 'object', |
||||||||||
304 | 'properties' => array( |
||||||||||
305 | 'id' => array( |
||||||||||
306 | 'description' => __( 'Unique identifier for the resource.', 'woocommerce-rest-api' ), |
||||||||||
307 | 'type' => 'integer', |
||||||||||
308 | 'context' => array( 'view', 'edit' ), |
||||||||||
309 | 'readonly' => true, |
||||||||||
310 | ), |
||||||||||
311 | 'parent_id' => array( |
||||||||||
312 | 'description' => __( 'Parent order ID.', 'woocommerce-rest-api' ), |
||||||||||
313 | 'type' => 'integer', |
||||||||||
314 | 'context' => array( 'view', 'edit' ), |
||||||||||
315 | ), |
||||||||||
316 | 'number' => array( |
||||||||||
317 | 'description' => __( 'Order number.', 'woocommerce-rest-api' ), |
||||||||||
318 | 'type' => 'string', |
||||||||||
319 | 'context' => array( 'view', 'edit' ), |
||||||||||
320 | 'readonly' => true, |
||||||||||
321 | ), |
||||||||||
322 | 'order_key' => array( |
||||||||||
323 | 'description' => __( 'Order key.', 'woocommerce-rest-api' ), |
||||||||||
324 | 'type' => 'string', |
||||||||||
325 | 'context' => array( 'view', 'edit' ), |
||||||||||
326 | 'readonly' => true, |
||||||||||
327 | ), |
||||||||||
328 | 'created_via' => array( |
||||||||||
329 | 'description' => __( 'Shows where the order was created.', 'woocommerce-rest-api' ), |
||||||||||
330 | 'type' => 'string', |
||||||||||
331 | 'context' => array( 'view', 'edit' ), |
||||||||||
332 | 'readonly' => true, |
||||||||||
333 | ), |
||||||||||
334 | 'version' => array( |
||||||||||
335 | 'description' => __( 'Version of WooCommerce which last updated the order.', 'woocommerce-rest-api' ), |
||||||||||
336 | 'type' => 'integer', |
||||||||||
337 | 'context' => array( 'view', 'edit' ), |
||||||||||
338 | 'readonly' => true, |
||||||||||
339 | ), |
||||||||||
340 | 'status' => array( |
||||||||||
341 | 'description' => __( 'Order status.', 'woocommerce-rest-api' ), |
||||||||||
342 | 'type' => 'string', |
||||||||||
343 | 'default' => 'pending', |
||||||||||
344 | 'enum' => $this->get_order_statuses(), |
||||||||||
345 | 'context' => array( 'view', 'edit' ), |
||||||||||
346 | ), |
||||||||||
347 | 'currency' => array( |
||||||||||
348 | 'description' => __( 'Currency the order was created with, in ISO format.', 'woocommerce-rest-api' ), |
||||||||||
349 | 'type' => 'string', |
||||||||||
350 | 'default' => get_woocommerce_currency(), |
||||||||||
351 | 'enum' => array_keys( get_woocommerce_currencies() ), |
||||||||||
352 | 'context' => array( 'view', 'edit' ), |
||||||||||
353 | ), |
||||||||||
354 | 'currency_symbol' => array( |
||||||||||
355 | 'description' => __( 'Currency symbol.', 'woocommerce-rest-api' ), |
||||||||||
356 | 'type' => 'string', |
||||||||||
357 | 'context' => array( 'view', 'edit' ), |
||||||||||
358 | 'readonly' => true, |
||||||||||
359 | ), |
||||||||||
360 | 'date_created' => array( |
||||||||||
361 | 'description' => __( "The date the order was created, in the site's timezone.", 'woocommerce-rest-api' ), |
||||||||||
362 | 'type' => 'date-time', |
||||||||||
363 | 'context' => array( 'view', 'edit' ), |
||||||||||
364 | 'readonly' => true, |
||||||||||
365 | ), |
||||||||||
366 | 'date_created_gmt' => array( |
||||||||||
367 | 'description' => __( 'The date the order was created, as GMT.', 'woocommerce-rest-api' ), |
||||||||||
368 | 'type' => 'date-time', |
||||||||||
369 | 'context' => array( 'view', 'edit' ), |
||||||||||
370 | 'readonly' => true, |
||||||||||
371 | ), |
||||||||||
372 | 'date_modified' => array( |
||||||||||
373 | 'description' => __( "The date the order was last modified, in the site's timezone.", 'woocommerce-rest-api' ), |
||||||||||
374 | 'type' => 'date-time', |
||||||||||
375 | 'context' => array( 'view', 'edit' ), |
||||||||||
376 | 'readonly' => true, |
||||||||||
377 | ), |
||||||||||
378 | 'date_modified_gmt' => array( |
||||||||||
379 | 'description' => __( 'The date the order was last modified, as GMT.', 'woocommerce-rest-api' ), |
||||||||||
380 | 'type' => 'date-time', |
||||||||||
381 | 'context' => array( 'view', 'edit' ), |
||||||||||
382 | 'readonly' => true, |
||||||||||
383 | ), |
||||||||||
384 | 'discount_total' => array( |
||||||||||
385 | 'description' => __( 'Total discount amount for the order.', 'woocommerce-rest-api' ), |
||||||||||
386 | 'type' => 'string', |
||||||||||
387 | 'context' => array( 'view', 'edit' ), |
||||||||||
388 | 'readonly' => true, |
||||||||||
389 | ), |
||||||||||
390 | 'discount_tax' => array( |
||||||||||
391 | 'description' => __( 'Total discount tax amount for the order.', 'woocommerce-rest-api' ), |
||||||||||
392 | 'type' => 'string', |
||||||||||
393 | 'context' => array( 'view', 'edit' ), |
||||||||||
394 | 'readonly' => true, |
||||||||||
395 | ), |
||||||||||
396 | 'shipping_total' => array( |
||||||||||
397 | 'description' => __( 'Total shipping amount for the order.', 'woocommerce-rest-api' ), |
||||||||||
398 | 'type' => 'string', |
||||||||||
399 | 'context' => array( 'view', 'edit' ), |
||||||||||
400 | 'readonly' => true, |
||||||||||
401 | ), |
||||||||||
402 | 'shipping_tax' => array( |
||||||||||
403 | 'description' => __( 'Total shipping tax amount for the order.', 'woocommerce-rest-api' ), |
||||||||||
404 | 'type' => 'string', |
||||||||||
405 | 'context' => array( 'view', 'edit' ), |
||||||||||
406 | 'readonly' => true, |
||||||||||
407 | ), |
||||||||||
408 | 'cart_tax' => array( |
||||||||||
409 | 'description' => __( 'Sum of line item taxes only.', 'woocommerce-rest-api' ), |
||||||||||
410 | 'type' => 'string', |
||||||||||
411 | 'context' => array( 'view', 'edit' ), |
||||||||||
412 | 'readonly' => true, |
||||||||||
413 | ), |
||||||||||
414 | 'total' => array( |
||||||||||
415 | 'description' => __( 'Grand total.', 'woocommerce-rest-api' ), |
||||||||||
416 | 'type' => 'string', |
||||||||||
417 | 'context' => array( 'view', 'edit' ), |
||||||||||
418 | 'readonly' => true, |
||||||||||
419 | ), |
||||||||||
420 | 'total_tax' => array( |
||||||||||
421 | 'description' => __( 'Sum of all taxes.', 'woocommerce-rest-api' ), |
||||||||||
422 | 'type' => 'string', |
||||||||||
423 | 'context' => array( 'view', 'edit' ), |
||||||||||
424 | 'readonly' => true, |
||||||||||
425 | ), |
||||||||||
426 | 'prices_include_tax' => array( |
||||||||||
427 | 'description' => __( 'True the prices included tax during checkout.', 'woocommerce-rest-api' ), |
||||||||||
428 | 'type' => 'boolean', |
||||||||||
429 | 'context' => array( 'view', 'edit' ), |
||||||||||
430 | 'readonly' => true, |
||||||||||
431 | ), |
||||||||||
432 | 'customer_id' => array( |
||||||||||
433 | 'description' => __( 'User ID who owns the order. 0 for guests.', 'woocommerce-rest-api' ), |
||||||||||
434 | 'type' => 'integer', |
||||||||||
435 | 'default' => 0, |
||||||||||
436 | 'context' => array( 'view', 'edit' ), |
||||||||||
437 | ), |
||||||||||
438 | 'customer_ip_address' => array( |
||||||||||
439 | 'description' => __( "Customer's IP address.", 'woocommerce-rest-api' ), |
||||||||||
440 | 'type' => 'string', |
||||||||||
441 | 'context' => array( 'view', 'edit' ), |
||||||||||
442 | 'readonly' => true, |
||||||||||
443 | ), |
||||||||||
444 | 'customer_user_agent' => array( |
||||||||||
445 | 'description' => __( 'User agent of the customer.', 'woocommerce-rest-api' ), |
||||||||||
446 | 'type' => 'string', |
||||||||||
447 | 'context' => array( 'view', 'edit' ), |
||||||||||
448 | 'readonly' => true, |
||||||||||
449 | ), |
||||||||||
450 | 'customer_note' => array( |
||||||||||
451 | 'description' => __( 'Note left by customer during checkout.', 'woocommerce-rest-api' ), |
||||||||||
452 | 'type' => 'string', |
||||||||||
453 | 'context' => array( 'view', 'edit' ), |
||||||||||
454 | ), |
||||||||||
455 | 'billing' => array( |
||||||||||
456 | 'description' => __( 'Billing address.', 'woocommerce-rest-api' ), |
||||||||||
457 | 'type' => 'object', |
||||||||||
458 | 'context' => array( 'view', 'edit' ), |
||||||||||
459 | 'properties' => array( |
||||||||||
460 | 'first_name' => array( |
||||||||||
461 | 'description' => __( 'First name.', 'woocommerce-rest-api' ), |
||||||||||
462 | 'type' => 'string', |
||||||||||
463 | 'context' => array( 'view', 'edit' ), |
||||||||||
464 | ), |
||||||||||
465 | 'last_name' => array( |
||||||||||
466 | 'description' => __( 'Last name.', 'woocommerce-rest-api' ), |
||||||||||
467 | 'type' => 'string', |
||||||||||
468 | 'context' => array( 'view', 'edit' ), |
||||||||||
469 | ), |
||||||||||
470 | 'company' => array( |
||||||||||
471 | 'description' => __( 'Company name.', 'woocommerce-rest-api' ), |
||||||||||
472 | 'type' => 'string', |
||||||||||
473 | 'context' => array( 'view', 'edit' ), |
||||||||||
474 | ), |
||||||||||
475 | 'address_1' => array( |
||||||||||
476 | 'description' => __( 'Address line 1', 'woocommerce-rest-api' ), |
||||||||||
477 | 'type' => 'string', |
||||||||||
478 | 'context' => array( 'view', 'edit' ), |
||||||||||
479 | ), |
||||||||||
480 | 'address_2' => array( |
||||||||||
481 | 'description' => __( 'Address line 2', 'woocommerce-rest-api' ), |
||||||||||
482 | 'type' => 'string', |
||||||||||
483 | 'context' => array( 'view', 'edit' ), |
||||||||||
484 | ), |
||||||||||
485 | 'city' => array( |
||||||||||
486 | 'description' => __( 'City name.', 'woocommerce-rest-api' ), |
||||||||||
487 | 'type' => 'string', |
||||||||||
488 | 'context' => array( 'view', 'edit' ), |
||||||||||
489 | ), |
||||||||||
490 | 'state' => array( |
||||||||||
491 | 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce-rest-api' ), |
||||||||||
492 | 'type' => 'string', |
||||||||||
493 | 'context' => array( 'view', 'edit' ), |
||||||||||
494 | ), |
||||||||||
495 | 'postcode' => array( |
||||||||||
496 | 'description' => __( 'Postal code.', 'woocommerce-rest-api' ), |
||||||||||
497 | 'type' => 'string', |
||||||||||
498 | 'context' => array( 'view', 'edit' ), |
||||||||||
499 | ), |
||||||||||
500 | 'country' => array( |
||||||||||
501 | 'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce-rest-api' ), |
||||||||||
502 | 'type' => 'string', |
||||||||||
503 | 'context' => array( 'view', 'edit' ), |
||||||||||
504 | ), |
||||||||||
505 | 'email' => array( |
||||||||||
506 | 'description' => __( 'Email address.', 'woocommerce-rest-api' ), |
||||||||||
507 | 'type' => 'string', |
||||||||||
508 | 'format' => 'email', |
||||||||||
509 | 'context' => array( 'view', 'edit' ), |
||||||||||
510 | ), |
||||||||||
511 | 'phone' => array( |
||||||||||
512 | 'description' => __( 'Phone number.', 'woocommerce-rest-api' ), |
||||||||||
513 | 'type' => 'string', |
||||||||||
514 | 'context' => array( 'view', 'edit' ), |
||||||||||
515 | ), |
||||||||||
516 | ), |
||||||||||
517 | ), |
||||||||||
518 | 'shipping' => array( |
||||||||||
519 | 'description' => __( 'Shipping address.', 'woocommerce-rest-api' ), |
||||||||||
520 | 'type' => 'object', |
||||||||||
521 | 'context' => array( 'view', 'edit' ), |
||||||||||
522 | 'properties' => array( |
||||||||||
523 | 'first_name' => array( |
||||||||||
524 | 'description' => __( 'First name.', 'woocommerce-rest-api' ), |
||||||||||
525 | 'type' => 'string', |
||||||||||
526 | 'context' => array( 'view', 'edit' ), |
||||||||||
527 | ), |
||||||||||
528 | 'last_name' => array( |
||||||||||
529 | 'description' => __( 'Last name.', 'woocommerce-rest-api' ), |
||||||||||
530 | 'type' => 'string', |
||||||||||
531 | 'context' => array( 'view', 'edit' ), |
||||||||||
532 | ), |
||||||||||
533 | 'company' => array( |
||||||||||
534 | 'description' => __( 'Company name.', 'woocommerce-rest-api' ), |
||||||||||
535 | 'type' => 'string', |
||||||||||
536 | 'context' => array( 'view', 'edit' ), |
||||||||||
537 | ), |
||||||||||
538 | 'address_1' => array( |
||||||||||
539 | 'description' => __( 'Address line 1', 'woocommerce-rest-api' ), |
||||||||||
540 | 'type' => 'string', |
||||||||||
541 | 'context' => array( 'view', 'edit' ), |
||||||||||
542 | ), |
||||||||||
543 | 'address_2' => array( |
||||||||||
544 | 'description' => __( 'Address line 2', 'woocommerce-rest-api' ), |
||||||||||
545 | 'type' => 'string', |
||||||||||
546 | 'context' => array( 'view', 'edit' ), |
||||||||||
547 | ), |
||||||||||
548 | 'city' => array( |
||||||||||
549 | 'description' => __( 'City name.', 'woocommerce-rest-api' ), |
||||||||||
550 | 'type' => 'string', |
||||||||||
551 | 'context' => array( 'view', 'edit' ), |
||||||||||
552 | ), |
||||||||||
553 | 'state' => array( |
||||||||||
554 | 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce-rest-api' ), |
||||||||||
555 | 'type' => 'string', |
||||||||||
556 | 'context' => array( 'view', 'edit' ), |
||||||||||
557 | ), |
||||||||||
558 | 'postcode' => array( |
||||||||||
559 | 'description' => __( 'Postal code.', 'woocommerce-rest-api' ), |
||||||||||
560 | 'type' => 'string', |
||||||||||
561 | 'context' => array( 'view', 'edit' ), |
||||||||||
562 | ), |
||||||||||
563 | 'country' => array( |
||||||||||
564 | 'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce-rest-api' ), |
||||||||||
565 | 'type' => 'string', |
||||||||||
566 | 'context' => array( 'view', 'edit' ), |
||||||||||
567 | ), |
||||||||||
568 | ), |
||||||||||
569 | ), |
||||||||||
570 | 'payment_method' => array( |
||||||||||
571 | 'description' => __( 'Payment method ID.', 'woocommerce-rest-api' ), |
||||||||||
572 | 'type' => 'string', |
||||||||||
573 | 'context' => array( 'view', 'edit' ), |
||||||||||
574 | ), |
||||||||||
575 | 'payment_method_title' => array( |
||||||||||
576 | 'description' => __( 'Payment method title.', 'woocommerce-rest-api' ), |
||||||||||
577 | 'type' => 'string', |
||||||||||
578 | 'context' => array( 'view', 'edit' ), |
||||||||||
579 | 'arg_options' => array( |
||||||||||
580 | 'sanitize_callback' => 'sanitize_text_field', |
||||||||||
581 | ), |
||||||||||
582 | ), |
||||||||||
583 | 'transaction_id' => array( |
||||||||||
584 | 'description' => __( 'Unique transaction ID.', 'woocommerce-rest-api' ), |
||||||||||
585 | 'type' => 'string', |
||||||||||
586 | 'context' => array( 'view', 'edit' ), |
||||||||||
587 | ), |
||||||||||
588 | 'date_paid' => array( |
||||||||||
589 | 'description' => __( "The date the order was paid, in the site's timezone.", 'woocommerce-rest-api' ), |
||||||||||
590 | 'type' => 'date-time', |
||||||||||
591 | 'context' => array( 'view', 'edit' ), |
||||||||||
592 | 'readonly' => true, |
||||||||||
593 | ), |
||||||||||
594 | 'date_paid_gmt' => array( |
||||||||||
595 | 'description' => __( 'The date the order was paid, as GMT.', 'woocommerce-rest-api' ), |
||||||||||
596 | 'type' => 'date-time', |
||||||||||
597 | 'context' => array( 'view', 'edit' ), |
||||||||||
598 | 'readonly' => true, |
||||||||||
599 | ), |
||||||||||
600 | 'date_completed' => array( |
||||||||||
601 | 'description' => __( "The date the order was completed, in the site's timezone.", 'woocommerce-rest-api' ), |
||||||||||
602 | 'type' => 'date-time', |
||||||||||
603 | 'context' => array( 'view', 'edit' ), |
||||||||||
604 | 'readonly' => true, |
||||||||||
605 | ), |
||||||||||
606 | 'date_completed_gmt' => array( |
||||||||||
607 | 'description' => __( 'The date the order was completed, as GMT.', 'woocommerce-rest-api' ), |
||||||||||
608 | 'type' => 'date-time', |
||||||||||
609 | 'context' => array( 'view', 'edit' ), |
||||||||||
610 | 'readonly' => true, |
||||||||||
611 | ), |
||||||||||
612 | 'cart_hash' => array( |
||||||||||
613 | 'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce-rest-api' ), |
||||||||||
614 | 'type' => 'string', |
||||||||||
615 | 'context' => array( 'view', 'edit' ), |
||||||||||
616 | 'readonly' => true, |
||||||||||
617 | ), |
||||||||||
618 | 'meta_data' => array( |
||||||||||
619 | 'description' => __( 'Meta data.', 'woocommerce-rest-api' ), |
||||||||||
620 | 'type' => 'array', |
||||||||||
621 | 'context' => array( 'view', 'edit' ), |
||||||||||
622 | 'items' => array( |
||||||||||
623 | 'type' => 'object', |
||||||||||
624 | 'properties' => array( |
||||||||||
625 | 'id' => array( |
||||||||||
626 | 'description' => __( 'Meta ID.', 'woocommerce-rest-api' ), |
||||||||||
627 | 'type' => 'integer', |
||||||||||
628 | 'context' => array( 'view', 'edit' ), |
||||||||||
629 | 'readonly' => true, |
||||||||||
630 | ), |
||||||||||
631 | 'key' => array( |
||||||||||
632 | 'description' => __( 'Meta key.', 'woocommerce-rest-api' ), |
||||||||||
633 | 'type' => 'string', |
||||||||||
634 | 'context' => array( 'view', 'edit' ), |
||||||||||
635 | ), |
||||||||||
636 | 'value' => array( |
||||||||||
637 | 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), |
||||||||||
638 | 'type' => 'mixed', |
||||||||||
639 | 'context' => array( 'view', 'edit' ), |
||||||||||
640 | ), |
||||||||||
641 | ), |
||||||||||
642 | ), |
||||||||||
643 | ), |
||||||||||
644 | 'line_items' => array( |
||||||||||
645 | 'description' => __( 'Line items data.', 'woocommerce-rest-api' ), |
||||||||||
646 | 'type' => 'array', |
||||||||||
647 | 'context' => array( 'view', 'edit' ), |
||||||||||
648 | 'items' => array( |
||||||||||
649 | 'type' => 'object', |
||||||||||
650 | 'properties' => array( |
||||||||||
651 | 'id' => array( |
||||||||||
652 | 'description' => __( 'Item ID.', 'woocommerce-rest-api' ), |
||||||||||
653 | 'type' => 'integer', |
||||||||||
654 | 'context' => array( 'view', 'edit' ), |
||||||||||
655 | 'readonly' => true, |
||||||||||
656 | ), |
||||||||||
657 | 'name' => array( |
||||||||||
658 | 'description' => __( 'Product name.', 'woocommerce-rest-api' ), |
||||||||||
659 | 'type' => 'mixed', |
||||||||||
660 | 'context' => array( 'view', 'edit' ), |
||||||||||
661 | ), |
||||||||||
662 | 'product_id' => array( |
||||||||||
663 | 'description' => __( 'Product ID.', 'woocommerce-rest-api' ), |
||||||||||
664 | 'type' => 'mixed', |
||||||||||
665 | 'context' => array( 'view', 'edit' ), |
||||||||||
666 | ), |
||||||||||
667 | 'variation_id' => array( |
||||||||||
668 | 'description' => __( 'Variation ID, if applicable.', 'woocommerce-rest-api' ), |
||||||||||
669 | 'type' => 'integer', |
||||||||||
670 | 'context' => array( 'view', 'edit' ), |
||||||||||
671 | ), |
||||||||||
672 | 'quantity' => array( |
||||||||||
673 | 'description' => __( 'Quantity ordered.', 'woocommerce-rest-api' ), |
||||||||||
674 | 'type' => 'integer', |
||||||||||
675 | 'context' => array( 'view', 'edit' ), |
||||||||||
676 | ), |
||||||||||
677 | 'tax_class' => array( |
||||||||||
678 | 'description' => __( 'Tax class of product.', 'woocommerce-rest-api' ), |
||||||||||
679 | 'type' => 'string', |
||||||||||
680 | 'context' => array( 'view', 'edit' ), |
||||||||||
681 | ), |
||||||||||
682 | 'subtotal' => array( |
||||||||||
683 | 'description' => __( 'Line subtotal (before discounts).', 'woocommerce-rest-api' ), |
||||||||||
684 | 'type' => 'string', |
||||||||||
685 | 'context' => array( 'view', 'edit' ), |
||||||||||
686 | ), |
||||||||||
687 | 'subtotal_tax' => array( |
||||||||||
688 | 'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce-rest-api' ), |
||||||||||
689 | 'type' => 'string', |
||||||||||
690 | 'context' => array( 'view', 'edit' ), |
||||||||||
691 | 'readonly' => true, |
||||||||||
692 | ), |
||||||||||
693 | 'total' => array( |
||||||||||
694 | 'description' => __( 'Line total (after discounts).', 'woocommerce-rest-api' ), |
||||||||||
695 | 'type' => 'string', |
||||||||||
696 | 'context' => array( 'view', 'edit' ), |
||||||||||
697 | ), |
||||||||||
698 | 'total_tax' => array( |
||||||||||
699 | 'description' => __( 'Line total tax (after discounts).', 'woocommerce-rest-api' ), |
||||||||||
700 | 'type' => 'string', |
||||||||||
701 | 'context' => array( 'view', 'edit' ), |
||||||||||
702 | 'readonly' => true, |
||||||||||
703 | ), |
||||||||||
704 | 'taxes' => array( |
||||||||||
705 | 'description' => __( 'Line taxes.', 'woocommerce-rest-api' ), |
||||||||||
706 | 'type' => 'array', |
||||||||||
707 | 'context' => array( 'view', 'edit' ), |
||||||||||
708 | 'readonly' => true, |
||||||||||
709 | 'items' => array( |
||||||||||
710 | 'type' => 'object', |
||||||||||
711 | 'properties' => array( |
||||||||||
712 | 'id' => array( |
||||||||||
713 | 'description' => __( 'Tax rate ID.', 'woocommerce-rest-api' ), |
||||||||||
714 | 'type' => 'integer', |
||||||||||
715 | 'context' => array( 'view', 'edit' ), |
||||||||||
716 | ), |
||||||||||
717 | 'total' => array( |
||||||||||
718 | 'description' => __( 'Tax total.', 'woocommerce-rest-api' ), |
||||||||||
719 | 'type' => 'string', |
||||||||||
720 | 'context' => array( 'view', 'edit' ), |
||||||||||
721 | ), |
||||||||||
722 | 'subtotal' => array( |
||||||||||
723 | 'description' => __( 'Tax subtotal.', 'woocommerce-rest-api' ), |
||||||||||
724 | 'type' => 'string', |
||||||||||
725 | 'context' => array( 'view', 'edit' ), |
||||||||||
726 | ), |
||||||||||
727 | ), |
||||||||||
728 | ), |
||||||||||
729 | ), |
||||||||||
730 | 'meta_data' => array( |
||||||||||
731 | 'description' => __( 'Meta data.', 'woocommerce-rest-api' ), |
||||||||||
732 | 'type' => 'array', |
||||||||||
733 | 'context' => array( 'view', 'edit' ), |
||||||||||
734 | 'items' => array( |
||||||||||
735 | 'type' => 'object', |
||||||||||
736 | 'properties' => array( |
||||||||||
737 | 'id' => array( |
||||||||||
738 | 'description' => __( 'Meta ID.', 'woocommerce-rest-api' ), |
||||||||||
739 | 'type' => 'integer', |
||||||||||
740 | 'context' => array( 'view', 'edit' ), |
||||||||||
741 | 'readonly' => true, |
||||||||||
742 | ), |
||||||||||
743 | 'key' => array( |
||||||||||
744 | 'description' => __( 'Meta key.', 'woocommerce-rest-api' ), |
||||||||||
745 | 'type' => 'string', |
||||||||||
746 | 'context' => array( 'view', 'edit' ), |
||||||||||
747 | ), |
||||||||||
748 | 'value' => array( |
||||||||||
749 | 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), |
||||||||||
750 | 'type' => 'mixed', |
||||||||||
751 | 'context' => array( 'view', 'edit' ), |
||||||||||
752 | ), |
||||||||||
753 | ), |
||||||||||
754 | ), |
||||||||||
755 | ), |
||||||||||
756 | 'sku' => array( |
||||||||||
757 | 'description' => __( 'Product SKU.', 'woocommerce-rest-api' ), |
||||||||||
758 | 'type' => 'string', |
||||||||||
759 | 'context' => array( 'view', 'edit' ), |
||||||||||
760 | 'readonly' => true, |
||||||||||
761 | ), |
||||||||||
762 | 'price' => array( |
||||||||||
763 | 'description' => __( 'Product price.', 'woocommerce-rest-api' ), |
||||||||||
764 | 'type' => 'number', |
||||||||||
765 | 'context' => array( 'view', 'edit' ), |
||||||||||
766 | 'readonly' => true, |
||||||||||
767 | ), |
||||||||||
768 | ), |
||||||||||
769 | ), |
||||||||||
770 | ), |
||||||||||
771 | 'tax_lines' => array( |
||||||||||
772 | 'description' => __( 'Tax lines data.', 'woocommerce-rest-api' ), |
||||||||||
773 | 'type' => 'array', |
||||||||||
774 | 'context' => array( 'view', 'edit' ), |
||||||||||
775 | 'readonly' => true, |
||||||||||
776 | 'items' => array( |
||||||||||
777 | 'type' => 'object', |
||||||||||
778 | 'properties' => array( |
||||||||||
779 | 'id' => array( |
||||||||||
780 | 'description' => __( 'Item ID.', 'woocommerce-rest-api' ), |
||||||||||
781 | 'type' => 'integer', |
||||||||||
782 | 'context' => array( 'view', 'edit' ), |
||||||||||
783 | 'readonly' => true, |
||||||||||
784 | ), |
||||||||||
785 | 'rate_code' => array( |
||||||||||
786 | 'description' => __( 'Tax rate code.', 'woocommerce-rest-api' ), |
||||||||||
787 | 'type' => 'string', |
||||||||||
788 | 'context' => array( 'view', 'edit' ), |
||||||||||
789 | 'readonly' => true, |
||||||||||
790 | ), |
||||||||||
791 | 'rate_id' => array( |
||||||||||
792 | 'description' => __( 'Tax rate ID.', 'woocommerce-rest-api' ), |
||||||||||
793 | 'type' => 'string', |
||||||||||
794 | 'context' => array( 'view', 'edit' ), |
||||||||||
795 | 'readonly' => true, |
||||||||||
796 | ), |
||||||||||
797 | 'label' => array( |
||||||||||
798 | 'description' => __( 'Tax rate label.', 'woocommerce-rest-api' ), |
||||||||||
799 | 'type' => 'string', |
||||||||||
800 | 'context' => array( 'view', 'edit' ), |
||||||||||
801 | 'readonly' => true, |
||||||||||
802 | ), |
||||||||||
803 | 'compound' => array( |
||||||||||
804 | 'description' => __( 'Show if is a compound tax rate.', 'woocommerce-rest-api' ), |
||||||||||
805 | 'type' => 'boolean', |
||||||||||
806 | 'context' => array( 'view', 'edit' ), |
||||||||||
807 | 'readonly' => true, |
||||||||||
808 | ), |
||||||||||
809 | 'tax_total' => array( |
||||||||||
810 | 'description' => __( 'Tax total (not including shipping taxes).', 'woocommerce-rest-api' ), |
||||||||||
811 | 'type' => 'string', |
||||||||||
812 | 'context' => array( 'view', 'edit' ), |
||||||||||
813 | 'readonly' => true, |
||||||||||
814 | ), |
||||||||||
815 | 'shipping_tax_total' => array( |
||||||||||
816 | 'description' => __( 'Shipping tax total.', 'woocommerce-rest-api' ), |
||||||||||
817 | 'type' => 'string', |
||||||||||
818 | 'context' => array( 'view', 'edit' ), |
||||||||||
819 | 'readonly' => true, |
||||||||||
820 | ), |
||||||||||
821 | 'meta_data' => array( |
||||||||||
822 | 'description' => __( 'Meta data.', 'woocommerce-rest-api' ), |
||||||||||
823 | 'type' => 'array', |
||||||||||
824 | 'context' => array( 'view', 'edit' ), |
||||||||||
825 | 'items' => array( |
||||||||||
826 | 'type' => 'object', |
||||||||||
827 | 'properties' => array( |
||||||||||
828 | 'id' => array( |
||||||||||
829 | 'description' => __( 'Meta ID.', 'woocommerce-rest-api' ), |
||||||||||
830 | 'type' => 'integer', |
||||||||||
831 | 'context' => array( 'view', 'edit' ), |
||||||||||
832 | 'readonly' => true, |
||||||||||
833 | ), |
||||||||||
834 | 'key' => array( |
||||||||||
835 | 'description' => __( 'Meta key.', 'woocommerce-rest-api' ), |
||||||||||
836 | 'type' => 'string', |
||||||||||
837 | 'context' => array( 'view', 'edit' ), |
||||||||||
838 | ), |
||||||||||
839 | 'value' => array( |
||||||||||
840 | 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), |
||||||||||
841 | 'type' => 'mixed', |
||||||||||
842 | 'context' => array( 'view', 'edit' ), |
||||||||||
843 | ), |
||||||||||
844 | ), |
||||||||||
845 | ), |
||||||||||
846 | ), |
||||||||||
847 | ), |
||||||||||
848 | ), |
||||||||||
849 | ), |
||||||||||
850 | 'shipping_lines' => array( |
||||||||||
851 | 'description' => __( 'Shipping lines data.', 'woocommerce-rest-api' ), |
||||||||||
852 | 'type' => 'array', |
||||||||||
853 | 'context' => array( 'view', 'edit' ), |
||||||||||
854 | 'items' => array( |
||||||||||
855 | 'type' => 'object', |
||||||||||
856 | 'properties' => array( |
||||||||||
857 | 'id' => array( |
||||||||||
858 | 'description' => __( 'Item ID.', 'woocommerce-rest-api' ), |
||||||||||
859 | 'type' => 'integer', |
||||||||||
860 | 'context' => array( 'view', 'edit' ), |
||||||||||
861 | 'readonly' => true, |
||||||||||
862 | ), |
||||||||||
863 | 'method_title' => array( |
||||||||||
864 | 'description' => __( 'Shipping method name.', 'woocommerce-rest-api' ), |
||||||||||
865 | 'type' => 'mixed', |
||||||||||
866 | 'context' => array( 'view', 'edit' ), |
||||||||||
867 | ), |
||||||||||
868 | 'method_id' => array( |
||||||||||
869 | 'description' => __( 'Shipping method ID.', 'woocommerce-rest-api' ), |
||||||||||
870 | 'type' => 'mixed', |
||||||||||
871 | 'context' => array( 'view', 'edit' ), |
||||||||||
872 | ), |
||||||||||
873 | 'instance_id' => array( |
||||||||||
874 | 'description' => __( 'Shipping instance ID.', 'woocommerce-rest-api' ), |
||||||||||
875 | 'type' => 'string', |
||||||||||
876 | 'context' => array( 'view', 'edit' ), |
||||||||||
877 | ), |
||||||||||
878 | 'total' => array( |
||||||||||
879 | 'description' => __( 'Line total (after discounts).', 'woocommerce-rest-api' ), |
||||||||||
880 | 'type' => 'string', |
||||||||||
881 | 'context' => array( 'view', 'edit' ), |
||||||||||
882 | ), |
||||||||||
883 | 'total_tax' => array( |
||||||||||
884 | 'description' => __( 'Line total tax (after discounts).', 'woocommerce-rest-api' ), |
||||||||||
885 | 'type' => 'string', |
||||||||||
886 | 'context' => array( 'view', 'edit' ), |
||||||||||
887 | 'readonly' => true, |
||||||||||
888 | ), |
||||||||||
889 | 'taxes' => array( |
||||||||||
890 | 'description' => __( 'Line taxes.', 'woocommerce-rest-api' ), |
||||||||||
891 | 'type' => 'array', |
||||||||||
892 | 'context' => array( 'view', 'edit' ), |
||||||||||
893 | 'readonly' => true, |
||||||||||
894 | 'items' => array( |
||||||||||
895 | 'type' => 'object', |
||||||||||
896 | 'properties' => array( |
||||||||||
897 | 'id' => array( |
||||||||||
898 | 'description' => __( 'Tax rate ID.', 'woocommerce-rest-api' ), |
||||||||||
899 | 'type' => 'integer', |
||||||||||
900 | 'context' => array( 'view', 'edit' ), |
||||||||||
901 | 'readonly' => true, |
||||||||||
902 | ), |
||||||||||
903 | 'total' => array( |
||||||||||
904 | 'description' => __( 'Tax total.', 'woocommerce-rest-api' ), |
||||||||||
905 | 'type' => 'string', |
||||||||||
906 | 'context' => array( 'view', 'edit' ), |
||||||||||
907 | 'readonly' => true, |
||||||||||
908 | ), |
||||||||||
909 | ), |
||||||||||
910 | ), |
||||||||||
911 | ), |
||||||||||
912 | 'meta_data' => array( |
||||||||||
913 | 'description' => __( 'Meta data.', 'woocommerce-rest-api' ), |
||||||||||
914 | 'type' => 'array', |
||||||||||
915 | 'context' => array( 'view', 'edit' ), |
||||||||||
916 | 'items' => array( |
||||||||||
917 | 'type' => 'object', |
||||||||||
918 | 'properties' => array( |
||||||||||
919 | 'id' => array( |
||||||||||
920 | 'description' => __( 'Meta ID.', 'woocommerce-rest-api' ), |
||||||||||
921 | 'type' => 'integer', |
||||||||||
922 | 'context' => array( 'view', 'edit' ), |
||||||||||
923 | 'readonly' => true, |
||||||||||
924 | ), |
||||||||||
925 | 'key' => array( |
||||||||||
926 | 'description' => __( 'Meta key.', 'woocommerce-rest-api' ), |
||||||||||
927 | 'type' => 'string', |
||||||||||
928 | 'context' => array( 'view', 'edit' ), |
||||||||||
929 | ), |
||||||||||
930 | 'value' => array( |
||||||||||
931 | 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), |
||||||||||
932 | 'type' => 'mixed', |
||||||||||
933 | 'context' => array( 'view', 'edit' ), |
||||||||||
934 | ), |
||||||||||
935 | ), |
||||||||||
936 | ), |
||||||||||
937 | ), |
||||||||||
938 | ), |
||||||||||
939 | ), |
||||||||||
940 | ), |
||||||||||
941 | 'fee_lines' => array( |
||||||||||
942 | 'description' => __( 'Fee lines data.', 'woocommerce-rest-api' ), |
||||||||||
943 | 'type' => 'array', |
||||||||||
944 | 'context' => array( 'view', 'edit' ), |
||||||||||
945 | 'items' => array( |
||||||||||
946 | 'type' => 'object', |
||||||||||
947 | 'properties' => array( |
||||||||||
948 | 'id' => array( |
||||||||||
949 | 'description' => __( 'Item ID.', 'woocommerce-rest-api' ), |
||||||||||
950 | 'type' => 'integer', |
||||||||||
951 | 'context' => array( 'view', 'edit' ), |
||||||||||
952 | 'readonly' => true, |
||||||||||
953 | ), |
||||||||||
954 | 'name' => array( |
||||||||||
955 | 'description' => __( 'Fee name.', 'woocommerce-rest-api' ), |
||||||||||
956 | 'type' => 'mixed', |
||||||||||
957 | 'context' => array( 'view', 'edit' ), |
||||||||||
958 | ), |
||||||||||
959 | 'tax_class' => array( |
||||||||||
960 | 'description' => __( 'Tax class of fee.', 'woocommerce-rest-api' ), |
||||||||||
961 | 'type' => 'string', |
||||||||||
962 | 'context' => array( 'view', 'edit' ), |
||||||||||
963 | ), |
||||||||||
964 | 'tax_status' => array( |
||||||||||
965 | 'description' => __( 'Tax status of fee.', 'woocommerce-rest-api' ), |
||||||||||
966 | 'type' => 'string', |
||||||||||
967 | 'context' => array( 'view', 'edit' ), |
||||||||||
968 | 'enum' => array( 'taxable', 'none' ), |
||||||||||
969 | ), |
||||||||||
970 | 'total' => array( |
||||||||||
971 | 'description' => __( 'Line total (after discounts).', 'woocommerce-rest-api' ), |
||||||||||
972 | 'type' => 'string', |
||||||||||
973 | 'context' => array( 'view', 'edit' ), |
||||||||||
974 | ), |
||||||||||
975 | 'total_tax' => array( |
||||||||||
976 | 'description' => __( 'Line total tax (after discounts).', 'woocommerce-rest-api' ), |
||||||||||
977 | 'type' => 'string', |
||||||||||
978 | 'context' => array( 'view', 'edit' ), |
||||||||||
979 | 'readonly' => true, |
||||||||||
980 | ), |
||||||||||
981 | 'taxes' => array( |
||||||||||
982 | 'description' => __( 'Line taxes.', 'woocommerce-rest-api' ), |
||||||||||
983 | 'type' => 'array', |
||||||||||
984 | 'context' => array( 'view', 'edit' ), |
||||||||||
985 | 'readonly' => true, |
||||||||||
986 | 'items' => array( |
||||||||||
987 | 'type' => 'object', |
||||||||||
988 | 'properties' => array( |
||||||||||
989 | 'id' => array( |
||||||||||
990 | 'description' => __( 'Tax rate ID.', 'woocommerce-rest-api' ), |
||||||||||
991 | 'type' => 'integer', |
||||||||||
992 | 'context' => array( 'view', 'edit' ), |
||||||||||
993 | 'readonly' => true, |
||||||||||
994 | ), |
||||||||||
995 | 'total' => array( |
||||||||||
996 | 'description' => __( 'Tax total.', 'woocommerce-rest-api' ), |
||||||||||
997 | 'type' => 'string', |
||||||||||
998 | 'context' => array( 'view', 'edit' ), |
||||||||||
999 | 'readonly' => true, |
||||||||||
1000 | ), |
||||||||||
1001 | 'subtotal' => array( |
||||||||||
1002 | 'description' => __( 'Tax subtotal.', 'woocommerce-rest-api' ), |
||||||||||
1003 | 'type' => 'string', |
||||||||||
1004 | 'context' => array( 'view', 'edit' ), |
||||||||||
1005 | 'readonly' => true, |
||||||||||
1006 | ), |
||||||||||
1007 | ), |
||||||||||
1008 | ), |
||||||||||
1009 | ), |
||||||||||
1010 | 'meta_data' => array( |
||||||||||
1011 | 'description' => __( 'Meta data.', 'woocommerce-rest-api' ), |
||||||||||
1012 | 'type' => 'array', |
||||||||||
1013 | 'context' => array( 'view', 'edit' ), |
||||||||||
1014 | 'items' => array( |
||||||||||
1015 | 'type' => 'object', |
||||||||||
1016 | 'properties' => array( |
||||||||||
1017 | 'id' => array( |
||||||||||
1018 | 'description' => __( 'Meta ID.', 'woocommerce-rest-api' ), |
||||||||||
1019 | 'type' => 'integer', |
||||||||||
1020 | 'context' => array( 'view', 'edit' ), |
||||||||||
1021 | 'readonly' => true, |
||||||||||
1022 | ), |
||||||||||
1023 | 'key' => array( |
||||||||||
1024 | 'description' => __( 'Meta key.', 'woocommerce-rest-api' ), |
||||||||||
1025 | 'type' => 'string', |
||||||||||
1026 | 'context' => array( 'view', 'edit' ), |
||||||||||
1027 | ), |
||||||||||
1028 | 'value' => array( |
||||||||||
1029 | 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), |
||||||||||
1030 | 'type' => 'mixed', |
||||||||||
1031 | 'context' => array( 'view', 'edit' ), |
||||||||||
1032 | ), |
||||||||||
1033 | ), |
||||||||||
1034 | ), |
||||||||||
1035 | ), |
||||||||||
1036 | ), |
||||||||||
1037 | ), |
||||||||||
1038 | ), |
||||||||||
1039 | 'coupon_lines' => array( |
||||||||||
1040 | 'description' => __( 'Coupons line data.', 'woocommerce-rest-api' ), |
||||||||||
1041 | 'type' => 'array', |
||||||||||
1042 | 'context' => array( 'view', 'edit' ), |
||||||||||
1043 | 'items' => array( |
||||||||||
1044 | 'type' => 'object', |
||||||||||
1045 | 'properties' => array( |
||||||||||
1046 | 'id' => array( |
||||||||||
1047 | 'description' => __( 'Item ID.', 'woocommerce-rest-api' ), |
||||||||||
1048 | 'type' => 'integer', |
||||||||||
1049 | 'context' => array( 'view', 'edit' ), |
||||||||||
1050 | 'readonly' => true, |
||||||||||
1051 | ), |
||||||||||
1052 | 'code' => array( |
||||||||||
1053 | 'description' => __( 'Coupon code.', 'woocommerce-rest-api' ), |
||||||||||
1054 | 'type' => 'mixed', |
||||||||||
1055 | 'context' => array( 'view', 'edit' ), |
||||||||||
1056 | ), |
||||||||||
1057 | 'discount' => array( |
||||||||||
1058 | 'description' => __( 'Discount total.', 'woocommerce-rest-api' ), |
||||||||||
1059 | 'type' => 'string', |
||||||||||
1060 | 'context' => array( 'view', 'edit' ), |
||||||||||
1061 | 'readonly' => true, |
||||||||||
1062 | ), |
||||||||||
1063 | 'discount_tax' => array( |
||||||||||
1064 | 'description' => __( 'Discount total tax.', 'woocommerce-rest-api' ), |
||||||||||
1065 | 'type' => 'string', |
||||||||||
1066 | 'context' => array( 'view', 'edit' ), |
||||||||||
1067 | 'readonly' => true, |
||||||||||
1068 | ), |
||||||||||
1069 | 'meta_data' => array( |
||||||||||
1070 | 'description' => __( 'Meta data.', 'woocommerce-rest-api' ), |
||||||||||
1071 | 'type' => 'array', |
||||||||||
1072 | 'context' => array( 'view', 'edit' ), |
||||||||||
1073 | 'items' => array( |
||||||||||
1074 | 'type' => 'object', |
||||||||||
1075 | 'properties' => array( |
||||||||||
1076 | 'id' => array( |
||||||||||
1077 | 'description' => __( 'Meta ID.', 'woocommerce-rest-api' ), |
||||||||||
1078 | 'type' => 'integer', |
||||||||||
1079 | 'context' => array( 'view', 'edit' ), |
||||||||||
1080 | 'readonly' => true, |
||||||||||
1081 | ), |
||||||||||
1082 | 'key' => array( |
||||||||||
1083 | 'description' => __( 'Meta key.', 'woocommerce-rest-api' ), |
||||||||||
1084 | 'type' => 'string', |
||||||||||
1085 | 'context' => array( 'view', 'edit' ), |
||||||||||
1086 | ), |
||||||||||
1087 | 'value' => array( |
||||||||||
1088 | 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), |
||||||||||
1089 | 'type' => 'mixed', |
||||||||||
1090 | 'context' => array( 'view', 'edit' ), |
||||||||||
1091 | ), |
||||||||||
1092 | ), |
||||||||||
1093 | ), |
||||||||||
1094 | ), |
||||||||||
1095 | ), |
||||||||||
1096 | ), |
||||||||||
1097 | ), |
||||||||||
1098 | 'refunds' => array( |
||||||||||
1099 | 'description' => __( 'List of refunds.', 'woocommerce-rest-api' ), |
||||||||||
1100 | 'type' => 'array', |
||||||||||
1101 | 'context' => array( 'view', 'edit' ), |
||||||||||
1102 | 'readonly' => true, |
||||||||||
1103 | 'items' => array( |
||||||||||
1104 | 'type' => 'object', |
||||||||||
1105 | 'properties' => array( |
||||||||||
1106 | 'id' => array( |
||||||||||
1107 | 'description' => __( 'Refund ID.', 'woocommerce-rest-api' ), |
||||||||||
1108 | 'type' => 'integer', |
||||||||||
1109 | 'context' => array( 'view', 'edit' ), |
||||||||||
1110 | 'readonly' => true, |
||||||||||
1111 | ), |
||||||||||
1112 | 'reason' => array( |
||||||||||
1113 | 'description' => __( 'Refund reason.', 'woocommerce-rest-api' ), |
||||||||||
1114 | 'type' => 'string', |
||||||||||
1115 | 'context' => array( 'view', 'edit' ), |
||||||||||
1116 | 'readonly' => true, |
||||||||||
1117 | ), |
||||||||||
1118 | 'total' => array( |
||||||||||
1119 | 'description' => __( 'Refund total.', 'woocommerce-rest-api' ), |
||||||||||
1120 | 'type' => 'string', |
||||||||||
1121 | 'context' => array( 'view', 'edit' ), |
||||||||||
1122 | 'readonly' => true, |
||||||||||
1123 | ), |
||||||||||
1124 | ), |
||||||||||
1125 | ), |
||||||||||
1126 | ), |
||||||||||
1127 | 'set_paid' => array( |
||||||||||
1128 | 'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce-rest-api' ), |
||||||||||
1129 | 'type' => 'boolean', |
||||||||||
1130 | 'default' => false, |
||||||||||
1131 | 'context' => array( 'edit' ), |
||||||||||
1132 | ), |
||||||||||
1133 | ), |
||||||||||
1134 | ); |
||||||||||
1135 | |||||||||||
1136 | return $this->add_additional_fields_schema( $schema ); |
||||||||||
1137 | } |
||||||||||
1138 | |||||||||||
1139 | /** |
||||||||||
1140 | * Get the query params for collections. |
||||||||||
1141 | * |
||||||||||
1142 | * @return array |
||||||||||
1143 | */ |
||||||||||
1144 | public function get_collection_params() { |
||||||||||
1145 | $params = parent::get_collection_params(); |
||||||||||
1146 | |||||||||||
1147 | $params['status'] = array( |
||||||||||
1148 | 'default' => 'any', |
||||||||||
1149 | 'description' => __( 'Limit result set to orders which have specific statuses.', 'woocommerce-rest-api' ), |
||||||||||
1150 | 'type' => 'array', |
||||||||||
1151 | 'items' => array( |
||||||||||
1152 | 'type' => 'string', |
||||||||||
1153 | 'enum' => array_merge( array( 'any', 'trash' ), $this->get_order_statuses() ), |
||||||||||
1154 | ), |
||||||||||
1155 | 'validate_callback' => 'rest_validate_request_arg', |
||||||||||
1156 | ); |
||||||||||
1157 | $params['customer'] = array( |
||||||||||
1158 | 'description' => __( 'Limit result set to orders assigned a specific customer.', 'woocommerce-rest-api' ), |
||||||||||
1159 | 'type' => 'integer', |
||||||||||
1160 | 'sanitize_callback' => 'absint', |
||||||||||
1161 | 'validate_callback' => 'rest_validate_request_arg', |
||||||||||
1162 | ); |
||||||||||
1163 | $params['product'] = array( |
||||||||||
1164 | 'description' => __( 'Limit result set to orders assigned a specific product.', 'woocommerce-rest-api' ), |
||||||||||
1165 | 'type' => 'integer', |
||||||||||
1166 | 'sanitize_callback' => 'absint', |
||||||||||
1167 | 'validate_callback' => 'rest_validate_request_arg', |
||||||||||
1168 | ); |
||||||||||
1169 | $params['dp'] = array( |
||||||||||
1170 | 'default' => wc_get_price_decimals(), |
||||||||||
1171 | 'description' => __( 'Number of decimal points to use in each resource.', 'woocommerce-rest-api' ), |
||||||||||
1172 | 'type' => 'integer', |
||||||||||
1173 | 'sanitize_callback' => 'absint', |
||||||||||
1174 | 'validate_callback' => 'rest_validate_request_arg', |
||||||||||
1175 | ); |
||||||||||
1176 | // This needs to remain a string to support extensions that filter Order Number. |
||||||||||
1177 | $params['number'] = array( |
||||||||||
1178 | 'description' => __( 'Limit result set to orders matching part of an order number.', 'woocommerce-rest-api' ), |
||||||||||
1179 | 'type' => 'string', |
||||||||||
1180 | 'validate_callback' => 'rest_validate_request_arg', |
||||||||||
1181 | ); |
||||||||||
1182 | |||||||||||
1183 | return $params; |
||||||||||
1184 | } |
||||||||||
1185 | } |
||||||||||
1186 |