Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes

CustomerHistory::query_cptprivateWC 1.0

Query customer order stats via the Analytics Customers report (legacy fallback when HPOS is not active).

Method of the class: CustomerHistory{}

No Hooks.

Returns

Object. Object with orders_count and total_spend properties.

Usage

// private - for code of main (parent) class only
$result = $this->query_cpt( $customer_report_id ): object;
$customer_report_id(int) (required)
The reports customer ID.

CustomerHistory::query_cpt() code WC 10.8.1

private function query_cpt( int $customer_report_id ): object {
	$args = array(
		'customers'    => array( $customer_report_id ),
		// If unset, these params have default values that affect the results.
		'order_after'  => null,
		'order_before' => null,
	);

	$customers_query = new CustomersQuery( $args );
	$customer_data   = $customers_query->get_data();
	$customer_row    = $customer_data->data[0] ?? null;

	return (object) array(
		'orders_count' => $customer_row['orders_count'] ?? 0,
		'total_spend'  => $customer_row['total_spend'] ?? 0,
	);
}