WordPress at Your Fingertips
function is not described


Controller::get_stats_data() public WC 1.0

Get report stats data, avoiding duplicate requests for stats that use the same endpoint.

{} It's a method of the class: Controller{}

No Hooks.


WP_REST_Response|WP_Error. Report stats data.


$Controller = new Controller();
$Controller->get_stats_data( $report, $query_args );
$report(string) (required)
Report slug to request data for.
$query_args(array) (required)
Report query args.

Code of Controller::get_stats_data() WC 6.1.0

public function get_stats_data( $report, $query_args ) {
	// Return from cache if we've already requested these report stats.
	if ( isset( $this->stats_data[ $report ] ) ) {
		return $this->stats_data[ $report ];

	// Request the report stats.
	$request_url = $this->endpoints[ $report ];
	$request     = new \WP_REST_Request( 'GET', $request_url );
	$request->set_param( 'before', $query_args['before'] );
	$request->set_param( 'after', $query_args['after'] );

	$response = rest_do_request( $request );

	// Cache the response.
	$this->stats_data[ $report ] = $response;

	return $response;