Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../includes/admin
File: class-wc-admin-reports.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Admin Reports
[2] Fix | Delete
*
[3] Fix | Delete
* Functions used for displaying sales and customer reports in admin.
[4] Fix | Delete
*
[5] Fix | Delete
* @author WooThemes
[6] Fix | Delete
* @category Admin
[7] Fix | Delete
* @package WooCommerce\Admin\Reports
[8] Fix | Delete
* @version 2.0.0
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[12] Fix | Delete
exit;
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
if ( class_exists( 'WC_Admin_Reports', false ) ) {
[16] Fix | Delete
return;
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* WC_Admin_Reports Class.
[21] Fix | Delete
*/
[22] Fix | Delete
class WC_Admin_Reports {
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Register the proper hook handlers.
[26] Fix | Delete
*/
[27] Fix | Delete
public static function register_hook_handlers() {
[28] Fix | Delete
add_filter( 'woocommerce_after_dashboard_status_widget_parameter', array( __CLASS__, 'get_report_instance' ) );
[29] Fix | Delete
add_filter( 'woocommerce_dashboard_status_widget_reports', array( __CLASS__, 'replace_dashboard_status_widget_reports' ) );
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Get an instance of WC_Admin_Report.
[34] Fix | Delete
*
[35] Fix | Delete
* @return WC_Admin_Report
[36] Fix | Delete
*/
[37] Fix | Delete
public static function get_report_instance() {
[38] Fix | Delete
include_once __DIR__ . '/reports/class-wc-admin-report.php';
[39] Fix | Delete
return new WC_Admin_Report();
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Filter handler for replacing the data of the status widget on the Dashboard page.
[44] Fix | Delete
*
[45] Fix | Delete
* @param array $status_widget_reports The data to display in the status widget.
[46] Fix | Delete
*/
[47] Fix | Delete
public static function replace_dashboard_status_widget_reports( $status_widget_reports ) {
[48] Fix | Delete
$report = self::get_report_instance();
[49] Fix | Delete
[50] Fix | Delete
include_once __DIR__ . '/reports/class-wc-report-sales-by-date.php';
[51] Fix | Delete
[52] Fix | Delete
$sales_by_date = new WC_Report_Sales_By_Date();
[53] Fix | Delete
$sales_by_date->start_date = strtotime( gmdate( 'Y-m-01', current_time( 'timestamp' ) ) ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
[54] Fix | Delete
$sales_by_date->end_date = strtotime( gmdate( 'Y-m-d', current_time( 'timestamp' ) ) ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
[55] Fix | Delete
$sales_by_date->chart_groupby = 'day';
[56] Fix | Delete
$sales_by_date->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)';
[57] Fix | Delete
[58] Fix | Delete
$status_widget_reports['net_sales_link'] = 'admin.php?page=wc-reports&tab=orders&range=month';
[59] Fix | Delete
$status_widget_reports['top_seller_link'] = 'admin.php?page=wc-reports&tab=orders&report=sales_by_product&range=month&product_ids=';
[60] Fix | Delete
$status_widget_reports['lowstock_link'] = 'admin.php?page=wc-reports&tab=stock&report=low_in_stock';
[61] Fix | Delete
$status_widget_reports['outofstock_link'] = 'admin.php?page=wc-reports&tab=stock&report=out_of_stock';
[62] Fix | Delete
$status_widget_reports['report_data'] = $sales_by_date->get_report_data();
[63] Fix | Delete
$status_widget_reports['get_sales_sparkline'] = array( $report, 'get_sales_sparkline' );
[64] Fix | Delete
[65] Fix | Delete
return $status_widget_reports;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Handles output of the reports page in admin.
[70] Fix | Delete
*/
[71] Fix | Delete
public static function output() {
[72] Fix | Delete
$reports = self::get_reports();
[73] Fix | Delete
$first_tab = array_keys( $reports );
[74] Fix | Delete
$current_tab = ! empty( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $reports ) ? sanitize_title( $_GET['tab'] ) : $first_tab[0];
[75] Fix | Delete
$current_report = isset( $_GET['report'] ) ? sanitize_title( $_GET['report'] ) : current( array_keys( $reports[ $current_tab ]['reports'] ) );
[76] Fix | Delete
[77] Fix | Delete
include_once dirname( __FILE__ ) . '/reports/class-wc-admin-report.php';
[78] Fix | Delete
include_once dirname( __FILE__ ) . '/views/html-admin-page-reports.php';
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Returns the definitions for the reports to show in admin.
[83] Fix | Delete
*
[84] Fix | Delete
* @return array
[85] Fix | Delete
*/
[86] Fix | Delete
public static function get_reports() {
[87] Fix | Delete
$reports = array(
[88] Fix | Delete
'orders' => array(
[89] Fix | Delete
'title' => __( 'Orders', 'woocommerce' ),
[90] Fix | Delete
'reports' => array(
[91] Fix | Delete
'sales_by_date' => array(
[92] Fix | Delete
'title' => __( 'Sales by date', 'woocommerce' ),
[93] Fix | Delete
'description' => '',
[94] Fix | Delete
'hide_title' => true,
[95] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[96] Fix | Delete
),
[97] Fix | Delete
'sales_by_product' => array(
[98] Fix | Delete
'title' => __( 'Sales by product', 'woocommerce' ),
[99] Fix | Delete
'description' => '',
[100] Fix | Delete
'hide_title' => true,
[101] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[102] Fix | Delete
),
[103] Fix | Delete
'sales_by_category' => array(
[104] Fix | Delete
'title' => __( 'Sales by category', 'woocommerce' ),
[105] Fix | Delete
'description' => '',
[106] Fix | Delete
'hide_title' => true,
[107] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[108] Fix | Delete
),
[109] Fix | Delete
'coupon_usage' => array(
[110] Fix | Delete
'title' => __( 'Coupons by date', 'woocommerce' ),
[111] Fix | Delete
'description' => '',
[112] Fix | Delete
'hide_title' => true,
[113] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[114] Fix | Delete
),
[115] Fix | Delete
'downloads' => array(
[116] Fix | Delete
'title' => __( 'Customer downloads', 'woocommerce' ),
[117] Fix | Delete
'description' => '',
[118] Fix | Delete
'hide_title' => true,
[119] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[120] Fix | Delete
),
[121] Fix | Delete
),
[122] Fix | Delete
),
[123] Fix | Delete
'customers' => array(
[124] Fix | Delete
'title' => __( 'Customers', 'woocommerce' ),
[125] Fix | Delete
'reports' => array(
[126] Fix | Delete
'customers' => array(
[127] Fix | Delete
'title' => __( 'Customers vs. guests', 'woocommerce' ),
[128] Fix | Delete
'description' => '',
[129] Fix | Delete
'hide_title' => true,
[130] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[131] Fix | Delete
),
[132] Fix | Delete
'customer_list' => array(
[133] Fix | Delete
'title' => __( 'Customer list', 'woocommerce' ),
[134] Fix | Delete
'description' => '',
[135] Fix | Delete
'hide_title' => true,
[136] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[137] Fix | Delete
),
[138] Fix | Delete
),
[139] Fix | Delete
),
[140] Fix | Delete
'stock' => array(
[141] Fix | Delete
'title' => __( 'Stock', 'woocommerce' ),
[142] Fix | Delete
'reports' => array(
[143] Fix | Delete
'low_in_stock' => array(
[144] Fix | Delete
'title' => __( 'Low in stock', 'woocommerce' ),
[145] Fix | Delete
'description' => '',
[146] Fix | Delete
'hide_title' => true,
[147] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[148] Fix | Delete
),
[149] Fix | Delete
'out_of_stock' => array(
[150] Fix | Delete
'title' => __( 'Out of stock', 'woocommerce' ),
[151] Fix | Delete
'description' => '',
[152] Fix | Delete
'hide_title' => true,
[153] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[154] Fix | Delete
),
[155] Fix | Delete
'most_stocked' => array(
[156] Fix | Delete
'title' => __( 'Most stocked', 'woocommerce' ),
[157] Fix | Delete
'description' => '',
[158] Fix | Delete
'hide_title' => true,
[159] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[160] Fix | Delete
),
[161] Fix | Delete
),
[162] Fix | Delete
),
[163] Fix | Delete
);
[164] Fix | Delete
[165] Fix | Delete
if ( wc_tax_enabled() ) {
[166] Fix | Delete
$reports['taxes'] = array(
[167] Fix | Delete
'title' => __( 'Taxes', 'woocommerce' ),
[168] Fix | Delete
'reports' => array(
[169] Fix | Delete
'taxes_by_code' => array(
[170] Fix | Delete
'title' => __( 'Taxes by code', 'woocommerce' ),
[171] Fix | Delete
'description' => '',
[172] Fix | Delete
'hide_title' => true,
[173] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[174] Fix | Delete
),
[175] Fix | Delete
'taxes_by_date' => array(
[176] Fix | Delete
'title' => __( 'Taxes by date', 'woocommerce' ),
[177] Fix | Delete
'description' => '',
[178] Fix | Delete
'hide_title' => true,
[179] Fix | Delete
'callback' => array( __CLASS__, 'get_report' ),
[180] Fix | Delete
),
[181] Fix | Delete
),
[182] Fix | Delete
);
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Filter the list and add reports to the legacy _WooCommerce > Reports_.
[187] Fix | Delete
*
[188] Fix | Delete
* Array items should be in the format of
[189] Fix | Delete
*
[190] Fix | Delete
* $reports['automatewoo'] = array(
[191] Fix | Delete
* 'title' => 'AutomateWoo',
[192] Fix | Delete
* 'reports' => array(
[193] Fix | Delete
* 'runs_by_date' => array(
[194] Fix | Delete
* 'title' => __( 'Workflow Runs', 'automatewoo' ),
[195] Fix | Delete
* 'description' => '',
[196] Fix | Delete
* 'hide_title' => false,
[197] Fix | Delete
* 'callback' => array( $this, 'get_runs_by_date' ),
[198] Fix | Delete
* ),
[199] Fix | Delete
* // ...
[200] Fix | Delete
* ),
[201] Fix | Delete
* );
[202] Fix | Delete
*
[203] Fix | Delete
* This filter has a colliding name with the one in Automattic\WooCommerce\Admin\API\Reports\Controller.
[204] Fix | Delete
* To make sure your code runs in the context of the legacy _WooCommerce > Reports_ screen, and not the REST endpoint,
[205] Fix | Delete
* use the following:
[206] Fix | Delete
*
[207] Fix | Delete
* add_filter( 'woocommerce_admin_reports',
[208] Fix | Delete
* function( $reports ) {
[209] Fix | Delete
* if ( is_admin() ) {
[210] Fix | Delete
* // ...
[211] Fix | Delete
*
[212] Fix | Delete
* @param array $reports The associative array of reports.
[213] Fix | Delete
*/
[214] Fix | Delete
$reports = apply_filters( 'woocommerce_admin_reports', $reports );
[215] Fix | Delete
$reports = apply_filters( 'woocommerce_reports_charts', $reports ); // Backwards compatibility.
[216] Fix | Delete
[217] Fix | Delete
foreach ( $reports as $key => &$report_group ) {
[218] Fix | Delete
if ( isset( $report_group['charts'] ) ) {
[219] Fix | Delete
$report_group['reports'] = $report_group['charts'];
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
// Silently ignore reports given for the filter in Automattic\WooCommerce\Admin\API\Reports\Controller.
[223] Fix | Delete
if ( ! isset( $report_group['reports'] ) ) {
[224] Fix | Delete
unset( $reports[ $key ] );
[225] Fix | Delete
continue;
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
foreach ( $report_group['reports'] as &$report ) {
[229] Fix | Delete
if ( isset( $report['function'] ) ) {
[230] Fix | Delete
$report['callback'] = $report['function'];
[231] Fix | Delete
}
[232] Fix | Delete
}
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
return $reports;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Get a report from our reports subfolder.
[240] Fix | Delete
*
[241] Fix | Delete
* @param string $name
[242] Fix | Delete
*/
[243] Fix | Delete
public static function get_report( $name ) {
[244] Fix | Delete
$name = sanitize_title( str_replace( '_', '-', $name ) );
[245] Fix | Delete
$class = 'WC_Report_' . str_replace( '-', '_', $name );
[246] Fix | Delete
[247] Fix | Delete
include_once apply_filters( 'wc_admin_reports_path', 'reports/class-wc-report-' . $name . '.php', $name, $class );
[248] Fix | Delete
[249] Fix | Delete
if ( ! class_exists( $class ) ) {
[250] Fix | Delete
return;
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
$report = new $class();
[254] Fix | Delete
$report->output_report();
[255] Fix | Delete
}
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function