WC_API_Reports::setup_report()privateWC 2.1

Setup the report object and parse any date filtering

Method of the class: WC_API_Reports{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->setup_report( $filter );
$filter(array) (required)
date filtering

Changelog

Since 2.1 Introduced.

WC_API_Reports::setup_report() code WC 8.7.0

private function setup_report( $filter ) {

	include_once( WC()->plugin_path() . '/includes/admin/reports/class-wc-admin-report.php' );
	include_once( WC()->plugin_path() . '/includes/admin/reports/class-wc-report-sales-by-date.php' );

	$this->report = new WC_Report_Sales_By_Date();

	if ( empty( $filter['period'] ) ) {

		// custom date range
		$filter['period'] = 'custom';

		if ( ! empty( $filter['date_min'] ) || ! empty( $filter['date_max'] ) ) {

			// overwrite _GET to make use of WC_Admin_Report::calculate_current_range() for custom date ranges
			$_GET['start_date'] = $this->server->parse_datetime( $filter['date_min'] );
			$_GET['end_date'] = isset( $filter['date_max'] ) ? $this->server->parse_datetime( $filter['date_max'] ) : null;

		} else {

			// default custom range to today
			$_GET['start_date'] = $_GET['end_date'] = date( 'Y-m-d', current_time( 'timestamp' ) );
		}
	} else {

		// ensure period is valid
		if ( ! in_array( $filter['period'], array( 'week', 'month', 'last_month', 'year' ) ) ) {
			$filter['period'] = 'week';
		}

		// TODO: change WC_Admin_Report class to use "week" instead, as it's more consistent with other periods
		// allow "week" for period instead of "7day"
		if ( 'week' === $filter['period'] ) {
			$filter['period'] = '7day';
		}
	}

	$this->report->calculate_current_range( $filter['period'] );
}