helper
1 year ago
importers
1 year ago
list-tables
1 year ago
marketplace-suggestions
1 year ago
meta-boxes
1 year ago
notes
1 year ago
plugin-updates
1 year ago
reports
1 year ago
settings
1 year ago
views
1 year ago
class-wc-admin-addons.php
1 year ago
class-wc-admin-api-keys-table-list.php
1 year ago
class-wc-admin-api-keys.php
1 year ago
class-wc-admin-assets.php
1 year ago
class-wc-admin-attributes.php
1 year ago
class-wc-admin-customize.php
1 year ago
class-wc-admin-dashboard-setup.php
1 year ago
class-wc-admin-dashboard.php
1 year ago
class-wc-admin-duplicate-product.php
1 year ago
class-wc-admin-exporters.php
1 year ago
class-wc-admin-help.php
1 year ago
class-wc-admin-importers.php
1 year ago
class-wc-admin-log-table-list.php
1 year ago
class-wc-admin-marketplace-promotions.php
1 year ago
class-wc-admin-menus.php
1 year ago
class-wc-admin-meta-boxes.php
1 year ago
class-wc-admin-notices.php
1 year ago
class-wc-admin-permalink-settings.php
1 year ago
class-wc-admin-pointers.php
1 year ago
class-wc-admin-post-types.php
1 year ago
class-wc-admin-profile.php
1 year ago
class-wc-admin-reports.php
1 year ago
class-wc-admin-settings.php
1 year ago
class-wc-admin-setup-wizard.php
1 year ago
class-wc-admin-status.php
1 year ago
class-wc-admin-taxonomies.php
1 year ago
class-wc-admin-upload-downloadable-product.php
1 year ago
class-wc-admin-webhooks-table-list.php
1 year ago
class-wc-admin-webhooks.php
1 year ago
class-wc-admin.php
1 year ago
wc-admin-functions.php
1 year ago
wc-meta-box-functions.php
1 year ago
class-wc-admin-reports.php
180 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin Reports |
| 4 | * |
| 5 | * Functions used for displaying sales and customer reports in admin. |
| 6 | * |
| 7 | * @author WooThemes |
| 8 | * @category Admin |
| 9 | * @package WooCommerce\Admin\Reports |
| 10 | * @version 2.0.0 |
| 11 | */ |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | if ( class_exists( 'WC_Admin_Reports', false ) ) { |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * WC_Admin_Reports Class. |
| 23 | */ |
| 24 | class WC_Admin_Reports { |
| 25 | |
| 26 | /** |
| 27 | * Handles output of the reports page in admin. |
| 28 | */ |
| 29 | public static function output() { |
| 30 | $reports = self::get_reports(); |
| 31 | $first_tab = array_keys( $reports ); |
| 32 | $current_tab = ! empty( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $reports ) ? sanitize_title( $_GET['tab'] ) : $first_tab[0]; |
| 33 | $current_report = isset( $_GET['report'] ) ? sanitize_title( $_GET['report'] ) : current( array_keys( $reports[ $current_tab ]['reports'] ) ); |
| 34 | |
| 35 | include_once dirname( __FILE__ ) . '/reports/class-wc-admin-report.php'; |
| 36 | include_once dirname( __FILE__ ) . '/views/html-admin-page-reports.php'; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns the definitions for the reports to show in admin. |
| 41 | * |
| 42 | * @return array |
| 43 | */ |
| 44 | public static function get_reports() { |
| 45 | $reports = array( |
| 46 | 'orders' => array( |
| 47 | 'title' => __( 'Orders', 'woocommerce' ), |
| 48 | 'reports' => array( |
| 49 | 'sales_by_date' => array( |
| 50 | 'title' => __( 'Sales by date', 'woocommerce' ), |
| 51 | 'description' => '', |
| 52 | 'hide_title' => true, |
| 53 | 'callback' => array( __CLASS__, 'get_report' ), |
| 54 | ), |
| 55 | 'sales_by_product' => array( |
| 56 | 'title' => __( 'Sales by product', 'woocommerce' ), |
| 57 | 'description' => '', |
| 58 | 'hide_title' => true, |
| 59 | 'callback' => array( __CLASS__, 'get_report' ), |
| 60 | ), |
| 61 | 'sales_by_category' => array( |
| 62 | 'title' => __( 'Sales by category', 'woocommerce' ), |
| 63 | 'description' => '', |
| 64 | 'hide_title' => true, |
| 65 | 'callback' => array( __CLASS__, 'get_report' ), |
| 66 | ), |
| 67 | 'coupon_usage' => array( |
| 68 | 'title' => __( 'Coupons by date', 'woocommerce' ), |
| 69 | 'description' => '', |
| 70 | 'hide_title' => true, |
| 71 | 'callback' => array( __CLASS__, 'get_report' ), |
| 72 | ), |
| 73 | 'downloads' => array( |
| 74 | 'title' => __( 'Customer downloads', 'woocommerce' ), |
| 75 | 'description' => '', |
| 76 | 'hide_title' => true, |
| 77 | 'callback' => array( __CLASS__, 'get_report' ), |
| 78 | ), |
| 79 | ), |
| 80 | ), |
| 81 | 'customers' => array( |
| 82 | 'title' => __( 'Customers', 'woocommerce' ), |
| 83 | 'reports' => array( |
| 84 | 'customers' => array( |
| 85 | 'title' => __( 'Customers vs. guests', 'woocommerce' ), |
| 86 | 'description' => '', |
| 87 | 'hide_title' => true, |
| 88 | 'callback' => array( __CLASS__, 'get_report' ), |
| 89 | ), |
| 90 | 'customer_list' => array( |
| 91 | 'title' => __( 'Customer list', 'woocommerce' ), |
| 92 | 'description' => '', |
| 93 | 'hide_title' => true, |
| 94 | 'callback' => array( __CLASS__, 'get_report' ), |
| 95 | ), |
| 96 | ), |
| 97 | ), |
| 98 | 'stock' => array( |
| 99 | 'title' => __( 'Stock', 'woocommerce' ), |
| 100 | 'reports' => array( |
| 101 | 'low_in_stock' => array( |
| 102 | 'title' => __( 'Low in stock', 'woocommerce' ), |
| 103 | 'description' => '', |
| 104 | 'hide_title' => true, |
| 105 | 'callback' => array( __CLASS__, 'get_report' ), |
| 106 | ), |
| 107 | 'out_of_stock' => array( |
| 108 | 'title' => __( 'Out of stock', 'woocommerce' ), |
| 109 | 'description' => '', |
| 110 | 'hide_title' => true, |
| 111 | 'callback' => array( __CLASS__, 'get_report' ), |
| 112 | ), |
| 113 | 'most_stocked' => array( |
| 114 | 'title' => __( 'Most stocked', 'woocommerce' ), |
| 115 | 'description' => '', |
| 116 | 'hide_title' => true, |
| 117 | 'callback' => array( __CLASS__, 'get_report' ), |
| 118 | ), |
| 119 | ), |
| 120 | ), |
| 121 | ); |
| 122 | |
| 123 | if ( wc_tax_enabled() ) { |
| 124 | $reports['taxes'] = array( |
| 125 | 'title' => __( 'Taxes', 'woocommerce' ), |
| 126 | 'reports' => array( |
| 127 | 'taxes_by_code' => array( |
| 128 | 'title' => __( 'Taxes by code', 'woocommerce' ), |
| 129 | 'description' => '', |
| 130 | 'hide_title' => true, |
| 131 | 'callback' => array( __CLASS__, 'get_report' ), |
| 132 | ), |
| 133 | 'taxes_by_date' => array( |
| 134 | 'title' => __( 'Taxes by date', 'woocommerce' ), |
| 135 | 'description' => '', |
| 136 | 'hide_title' => true, |
| 137 | 'callback' => array( __CLASS__, 'get_report' ), |
| 138 | ), |
| 139 | ), |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | $reports = apply_filters( 'woocommerce_admin_reports', $reports ); |
| 144 | $reports = apply_filters( 'woocommerce_reports_charts', $reports ); // Backwards compatibility. |
| 145 | |
| 146 | foreach ( $reports as $key => $report_group ) { |
| 147 | if ( isset( $reports[ $key ]['charts'] ) ) { |
| 148 | $reports[ $key ]['reports'] = $reports[ $key ]['charts']; |
| 149 | } |
| 150 | |
| 151 | foreach ( $reports[ $key ]['reports'] as $report_key => $report ) { |
| 152 | if ( isset( $reports[ $key ]['reports'][ $report_key ]['function'] ) ) { |
| 153 | $reports[ $key ]['reports'][ $report_key ]['callback'] = $reports[ $key ]['reports'][ $report_key ]['function']; |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return $reports; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Get a report from our reports subfolder. |
| 163 | * |
| 164 | * @param string $name |
| 165 | */ |
| 166 | public static function get_report( $name ) { |
| 167 | $name = sanitize_title( str_replace( '_', '-', $name ) ); |
| 168 | $class = 'WC_Report_' . str_replace( '-', '_', $name ); |
| 169 | |
| 170 | include_once apply_filters( 'wc_admin_reports_path', 'reports/class-wc-report-' . $name . '.php', $name, $class ); |
| 171 | |
| 172 | if ( ! class_exists( $class ) ) { |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | $report = new $class(); |
| 177 | $report->output_report(); |
| 178 | } |
| 179 | } |
| 180 |