WC_REST_Orders_Controller::prepare_objects_query
Prepare objects query.
Метод класса: WC_REST_Orders_Controller{}
Хуков нет.
Возвращает
array.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->prepare_objects_query( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Список изменений
| С версии 3.0.0 | Введена. |
Код WC_REST_Orders_Controller::prepare_objects_query() WC REST Orders Controller::prepare objects query WC 11.2.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;
}