WC_REST_Report_Sales_V1_Controller::setup_report()
Setup the report object and parse any date filtering.
Method of the class: WC_REST_Report_Sales_V1_Controller{}
No Hooks.
Return
null
. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->setup_report( $filter );
- $filter(array) (required)
- date filtering
WC_REST_Report_Sales_V1_Controller::setup_report() WC REST Report Sales V1 Controller::setup report code WC 9.7.1
protected 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'] = $filter['date_min']; $_GET['end_date'] = isset( $filter['date_max'] ) ? $filter['date_max'] : null; } else { // Default custom range to today. $_GET['start_date'] = $_GET['end_date'] = date( 'Y-m-d', current_time( 'timestamp' ) ); } } else { $filter['period'] = empty( $filter['period'] ) ? 'week' : $filter['period']; // Change "week" period to "7day". if ( 'week' === $filter['period'] ) { $filter['period'] = '7day'; } } $this->report->calculate_current_range( $filter['period'] ); }