WC_API_Customers::get_customer_orders()publicWC 2.1

Get the orders for a customer

Метод класса: WC_API_Customers{}

Хуки из метода

Возвращает

Массив|WP_Error.

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

$WC_API_Customers = new WC_API_Customers();
$WC_API_Customers->get_customer_orders( $id, $fields );
$id(int) (обязательный)
the customer ID
$fields(строка)
fields to include in response
По умолчанию: null

Список изменений

С версии 2.1 Введена.

Код WC_API_Customers::get_customer_orders() WC 7.7.2

public function get_customer_orders( $id, $fields = null ) {
	global $wpdb;

	$id = $this->validate_request( $id, 'customer', 'read' );

	if ( is_wp_error( $id ) ) {
		return $id;
	}

	$order_ids = wc_get_orders( array(
		'customer' => $id,
		'limit'    => -1,
		'orderby'  => 'date',
		'order'    => 'ASC',
		'return'   => 'ids',
	) );

	if ( empty( $order_ids ) ) {
		return array( 'orders' => array() );
	}

	$orders = array();

	foreach ( $order_ids as $order_id ) {
		$orders[] = current( WC()->api->WC_API_Orders->get_order( $order_id, $fields ) );
	}

	return array( 'orders' => apply_filters( 'woocommerce_api_customer_orders_response', $orders, $id, $fields, $order_ids, $this->server ) );
}