2011-09-16 08:30:16 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-11-03 13:53:50 +00:00
|
|
|
* Admin Reports
|
2012-08-14 12:21:34 +00:00
|
|
|
*
|
|
|
|
* Functions used for displaying sales and customer reports in admin.
|
2011-09-16 08:30:16 +00:00
|
|
|
*
|
2014-11-30 06:52:32 +00:00
|
|
|
* @author WooThemes
|
|
|
|
* @category Admin
|
|
|
|
* @package WooCommerce/Admin/Reports
|
2012-12-03 19:19:58 +00:00
|
|
|
* @version 2.0.0
|
2011-09-16 08:30:16 +00:00
|
|
|
*/
|
|
|
|
|
2014-09-20 19:52:30 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
2017-11-13 15:36:22 +00:00
|
|
|
exit;
|
2014-09-20 19:52:30 +00:00
|
|
|
}
|
2012-10-15 10:32:24 +00:00
|
|
|
|
2017-11-13 15:36:22 +00:00
|
|
|
if ( class_exists( 'WC_Admin_Reports', false ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-18 14:22:05 +00:00
|
|
|
|
2012-08-14 12:21:34 +00:00
|
|
|
/**
|
2015-11-03 12:28:01 +00:00
|
|
|
* WC_Admin_Reports Class.
|
2012-08-14 12:21:34 +00:00
|
|
|
*/
|
2013-06-22 10:37:59 +00:00
|
|
|
class WC_Admin_Reports {
|
|
|
|
|
|
|
|
/**
|
2013-07-18 14:22:05 +00:00
|
|
|
* Handles output of the reports page in admin.
|
2013-06-22 10:37:59 +00:00
|
|
|
*/
|
2014-03-20 11:10:25 +00:00
|
|
|
public static function output() {
|
|
|
|
$reports = self::get_reports();
|
2013-07-18 14:22:05 +00:00
|
|
|
$first_tab = array_keys( $reports );
|
2014-01-26 09:19:17 +00:00
|
|
|
$current_tab = ! empty( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : $first_tab[0];
|
|
|
|
$current_report = isset( $_GET['report'] ) ? sanitize_title( $_GET['report'] ) : current( array_keys( $reports[ $current_tab ]['reports'] ) );
|
2012-08-14 12:21:34 +00:00
|
|
|
|
2016-07-27 10:58:43 +00:00
|
|
|
include_once( dirname( __FILE__ ) . '/reports/class-wc-admin-report.php' );
|
|
|
|
include_once( dirname( __FILE__ ) . '/views/html-admin-page-reports.php' );
|
2013-06-22 10:37:59 +00:00
|
|
|
}
|
2012-08-14 12:21:34 +00:00
|
|
|
|
2013-06-22 10:37:59 +00:00
|
|
|
/**
|
|
|
|
* Returns the definitions for the reports to show in admin.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-03-20 11:10:25 +00:00
|
|
|
public static function get_reports() {
|
2013-06-22 10:37:59 +00:00
|
|
|
$reports = array(
|
2013-06-28 16:33:37 +00:00
|
|
|
'orders' => array(
|
|
|
|
'title' => __( 'Orders', 'woocommerce' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
'reports' => array(
|
2017-11-13 15:36:22 +00:00
|
|
|
'sales_by_date' => array(
|
2013-06-25 13:59:20 +00:00
|
|
|
'title' => __( 'Sales by date', 'woocommerce' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
'description' => '',
|
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
),
|
2017-11-13 15:36:22 +00:00
|
|
|
'sales_by_product' => array(
|
2013-06-26 14:11:33 +00:00
|
|
|
'title' => __( 'Sales by product', 'woocommerce' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
'description' => '',
|
2013-06-27 15:12:17 +00:00
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
),
|
2017-11-13 15:36:22 +00:00
|
|
|
'sales_by_category' => array(
|
2013-06-22 10:37:59 +00:00
|
|
|
'title' => __( 'Sales by category', 'woocommerce' ),
|
|
|
|
'description' => '',
|
2013-06-27 17:39:55 +00:00
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
),
|
2017-11-13 15:36:22 +00:00
|
|
|
'coupon_usage' => array(
|
2013-07-08 15:36:09 +00:00
|
|
|
'title' => __( 'Coupons by date', 'woocommerce' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
'description' => '',
|
2013-07-08 15:36:09 +00:00
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
|
|
|
),
|
2017-11-13 15:36:22 +00:00
|
|
|
'downloads' => array(
|
|
|
|
'title' => __( 'Customer downloads', 'woocommerce' ),
|
|
|
|
'description' => '',
|
2017-11-13 19:03:08 +00:00
|
|
|
'hide_title' => true,
|
2017-11-13 15:36:22 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
|
|
|
),
|
2016-08-27 01:46:45 +00:00
|
|
|
),
|
2013-06-22 10:37:59 +00:00
|
|
|
),
|
|
|
|
'customers' => array(
|
|
|
|
'title' => __( 'Customers', 'woocommerce' ),
|
|
|
|
'reports' => array(
|
2017-11-13 15:36:22 +00:00
|
|
|
'customers' => array(
|
2016-10-12 10:16:30 +00:00
|
|
|
'title' => __( 'Customers vs. guests', 'woocommerce' ),
|
2013-07-09 14:45:42 +00:00
|
|
|
'description' => '',
|
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
2013-07-09 14:45:42 +00:00
|
|
|
),
|
2017-11-13 15:36:22 +00:00
|
|
|
'customer_list' => array(
|
2016-10-12 10:16:30 +00:00
|
|
|
'title' => __( 'Customer list', 'woocommerce' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
'description' => '',
|
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
),
|
2016-08-27 01:46:45 +00:00
|
|
|
),
|
2013-06-22 10:37:59 +00:00
|
|
|
),
|
|
|
|
'stock' => array(
|
|
|
|
'title' => __( 'Stock', 'woocommerce' ),
|
|
|
|
'reports' => array(
|
2017-11-13 15:36:22 +00:00
|
|
|
'low_in_stock' => array(
|
2013-07-09 10:48:56 +00:00
|
|
|
'title' => __( 'Low in stock', 'woocommerce' ),
|
|
|
|
'description' => '',
|
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
2013-07-09 10:48:56 +00:00
|
|
|
),
|
2017-11-13 15:36:22 +00:00
|
|
|
'out_of_stock' => array(
|
2013-07-09 10:48:56 +00:00
|
|
|
'title' => __( 'Out of stock', 'woocommerce' ),
|
|
|
|
'description' => '',
|
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
2013-07-09 10:48:56 +00:00
|
|
|
),
|
2017-11-13 15:36:22 +00:00
|
|
|
'most_stocked' => array(
|
2017-08-23 03:01:35 +00:00
|
|
|
'title' => __( 'Most stocked', 'woocommerce' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
'description' => '',
|
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
2013-06-22 10:37:59 +00:00
|
|
|
),
|
2016-08-27 01:46:45 +00:00
|
|
|
),
|
|
|
|
),
|
2013-06-22 10:37:59 +00:00
|
|
|
);
|
2012-08-14 12:21:34 +00:00
|
|
|
|
2014-11-18 16:45:29 +00:00
|
|
|
if ( wc_tax_enabled() ) {
|
2013-06-26 14:11:33 +00:00
|
|
|
$reports['taxes'] = array(
|
2013-07-10 11:06:29 +00:00
|
|
|
'title' => __( 'Taxes', 'woocommerce' ),
|
2013-06-26 14:11:33 +00:00
|
|
|
'reports' => array(
|
2017-11-13 15:36:22 +00:00
|
|
|
'taxes_by_code' => array(
|
2013-07-10 11:05:45 +00:00
|
|
|
'title' => __( 'Taxes by code', 'woocommerce' ),
|
2013-06-26 14:11:33 +00:00
|
|
|
'description' => '',
|
2013-07-10 11:05:45 +00:00
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
2013-07-10 11:05:45 +00:00
|
|
|
),
|
2017-11-13 15:36:22 +00:00
|
|
|
'taxes_by_date' => array(
|
2013-07-10 11:05:45 +00:00
|
|
|
'title' => __( 'Taxes by date', 'woocommerce' ),
|
|
|
|
'description' => '',
|
|
|
|
'hide_title' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'callback' => array( __CLASS__, 'get_report' ),
|
2013-07-10 11:05:45 +00:00
|
|
|
),
|
2016-08-27 01:46:45 +00:00
|
|
|
),
|
2013-06-22 10:37:59 +00:00
|
|
|
);
|
|
|
|
}
|
2012-08-14 12:21:34 +00:00
|
|
|
|
2013-06-22 10:37:59 +00:00
|
|
|
$reports = apply_filters( 'woocommerce_admin_reports', $reports );
|
2017-07-17 10:10:52 +00:00
|
|
|
$reports = apply_filters( 'woocommerce_reports_charts', $reports ); // Backwards compatibility.
|
2012-08-14 12:21:34 +00:00
|
|
|
|
2013-06-22 10:37:59 +00:00
|
|
|
foreach ( $reports as $key => $report_group ) {
|
2014-03-20 11:10:25 +00:00
|
|
|
if ( isset( $reports[ $key ]['charts'] ) ) {
|
2013-07-08 11:57:56 +00:00
|
|
|
$reports[ $key ]['reports'] = $reports[ $key ]['charts'];
|
2014-03-20 11:10:25 +00:00
|
|
|
}
|
2012-08-14 12:21:34 +00:00
|
|
|
|
2013-07-08 11:57:56 +00:00
|
|
|
foreach ( $reports[ $key ]['reports'] as $report_key => $report ) {
|
2014-03-20 11:10:25 +00:00
|
|
|
if ( isset( $reports[ $key ]['reports'][ $report_key ]['function'] ) ) {
|
2013-07-08 11:57:56 +00:00
|
|
|
$reports[ $key ]['reports'][ $report_key ]['callback'] = $reports[ $key ]['reports'][ $report_key ]['function'];
|
2014-03-20 11:10:25 +00:00
|
|
|
}
|
2013-06-22 10:37:59 +00:00
|
|
|
}
|
2012-06-12 17:26:34 +00:00
|
|
|
}
|
2013-04-29 14:17:03 +00:00
|
|
|
|
2013-06-22 10:37:59 +00:00
|
|
|
return $reports;
|
|
|
|
}
|
2012-08-14 12:21:34 +00:00
|
|
|
|
2013-06-24 16:47:28 +00:00
|
|
|
/**
|
2015-11-03 12:28:01 +00:00
|
|
|
* Get a report from our reports subfolder.
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
2013-06-24 16:47:28 +00:00
|
|
|
*/
|
2014-03-20 11:10:25 +00:00
|
|
|
public static function get_report( $name ) {
|
2013-06-26 14:11:33 +00:00
|
|
|
$name = sanitize_title( str_replace( '_', '-', $name ) );
|
|
|
|
$class = 'WC_Report_' . str_replace( '-', '_', $name );
|
2013-06-25 13:59:20 +00:00
|
|
|
|
2014-05-14 23:54:45 +00:00
|
|
|
include_once( apply_filters( 'wc_admin_reports_path', 'reports/class-wc-report-' . $name . '.php', $name, $class ) );
|
2012-03-18 13:26:04 +00:00
|
|
|
|
2017-03-07 20:24:24 +00:00
|
|
|
if ( ! class_exists( $class ) ) {
|
2013-06-26 14:11:33 +00:00
|
|
|
return;
|
2017-03-07 20:24:24 +00:00
|
|
|
}
|
2012-08-14 12:21:34 +00:00
|
|
|
|
2013-06-26 14:11:33 +00:00
|
|
|
$report = new $class();
|
|
|
|
$report->output_report();
|
|
|
|
}
|
|
|
|
}
|