WC_REST_Orders_Controller::prepare_objects_query
Prepare objects query.
Method of the class: WC_REST_Orders_Controller{}
No Hooks.
Returns
Array.
Usage
// protected - for code of main (parent) or child class $result = $this->prepare_objects_query( $request );
- $request(WP_REST_Request) (required)
- Full details about the request.
Changelog
| Since 3.0.0 | Introduced. |
WC_REST_Orders_Controller::prepare_objects_query() WC REST Orders Controller::prepare objects query code WC 10.6.2
protected function prepare_objects_query( $request ) {
// This is needed to get around an array to string notice in WC_REST_Orders_V2_Controller::prepare_objects_query.
$statuses = $request['status'];
unset( $request['status'] );
$args = parent::prepare_objects_query( $request );
$args['post_status'] = array();
foreach ( $statuses as $status ) {
if ( in_array( $status, $this->get_order_statuses(), true ) ) {
$args['post_status'][] = 'wc-' . $status;
} elseif ( 'any' === $status ) {
// Set status to "any" and short-circuit out.
$args['post_status'] = 'any';
break;
} else {
$args['post_status'][] = $status;
}
}
// If created_via filter is provided, add it to query args.
if ( ! empty( $request['created_via'] ) ) {
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
$args['created_via'] = $request['created_via'];
} else {
$args['meta_query'][] = array(
'key' => '_created_via',
'value' => $request['created_via'],
'compare' => 'IN',
);
}
}
// Put the statuses back for further processing (next/prev links, etc).
$request['status'] = $statuses;
return $args;
}