WC_REST_Orders_Controller::prepare_objects_query()protectedWC 3.0.0

Prepare objects query.

{} Это метод класса: WC_REST_Orders_Controller{}

Хуков нет.

Возвращает

Массив.

Использование

// 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 6.9.4

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'] );

	// Prevents WC_REST_Orders_V2_Controller::prepare_objects_query() from generating a meta_query for 'customer'.
	// which COT can handle as a native field.
	$cot_customer =
		( OrderUtil::custom_orders_table_usage_is_enabled() && isset( $request['customer'] ) )
		? $request['customer']
		: null;

	if ( $cot_customer ) {
		unset( $request['customer'] );
	}

	$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;
		}
	}

	// Put the statuses back for further processing (next/prev links, etc).
	$request['status'] = $statuses;

	// Add back 'customer' to args and request.
	if ( ! is_null( $cot_customer ) ) {
		$args['customer']    = $cot_customer;
		$request['customer'] = $cot_customer;
	}

	return $args;
}