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' ) ) exit; // Exit if accessed directly
 14 
 15 if ( ! class_exists( 'WC_Admin_Reports' ) ) :
 16 
 17 /**
 18  * WC_Admin_Reports Class
 19  */
 20 class WC_Admin_Reports {
 21 
 22     /**
 23      * Handles output of the reports page in admin.
 24      */
 25     public static function output() {
 26         $reports        = self::get_reports();
 27         $first_tab      = array_keys( $reports );
 28         $current_tab    = ! empty( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : $first_tab[0];
 29         $current_report = isset( $_GET['report'] ) ? sanitize_title( $_GET['report'] ) : current( array_keys( $reports[ $current_tab ]['reports'] ) );
 30 
 31         include_once( 'reports/class-wc-admin-report.php' );
 32         include_once( 'views/html-admin-page-reports.php' );
 33     }
 34 
 35     /**
 36      * Returns the definitions for the reports to show in admin.
 37      *
 38      * @return array
 39      */
 40     public static function get_reports() {
 41         $reports = array(
 42             'orders'     => array(
 43                 'title'  => __( 'Orders', 'woocommerce' ),
 44                 'reports' => array(
 45                     "sales_by_date"    => array(
 46                         'title'       => __( 'Sales by date', 'woocommerce' ),
 47                         'description' => '',
 48                         'hide_title'  => true,
 49                         'callback'    => array( __CLASS__, 'get_report' )
 50                     ),
 51                     "sales_by_product"     => array(
 52                         'title'       => __( 'Sales by product', 'woocommerce' ),
 53                         'description' => '',
 54                         'hide_title'  => true,
 55                         'callback'    => array( __CLASS__, 'get_report' )
 56                     ),
 57                     "sales_by_category" => array(
 58                         'title'       => __( 'Sales by category', 'woocommerce' ),
 59                         'description' => '',
 60                         'hide_title'  => true,
 61                         'callback'    => array( __CLASS__, 'get_report' )
 62                     ),
 63                     "coupon_usage" => array(
 64                         'title'       => __( 'Coupons by date', 'woocommerce' ),
 65                         'description' => '',
 66                         'hide_title'  => true,
 67                         'callback'    => array( __CLASS__, 'get_report' )
 68                     )
 69                 )
 70             ),
 71             'customers' => array(
 72                 'title'  => __( 'Customers', 'woocommerce' ),
 73                 'reports' => array(
 74                     "customers" => array(
 75                         'title'       => __( 'Customers vs. Guests', 'woocommerce' ),
 76                         'description' => '',
 77                         'hide_title'  => true,
 78                         'callback'    => array( __CLASS__, 'get_report' )
 79                     ),
 80                     "customer_list" => array(
 81                         'title'       => __( 'Customer List', 'woocommerce' ),
 82                         'description' => '',
 83                         'hide_title'  => true,
 84                         'callback'    => array( __CLASS__, 'get_report' )
 85                     ),
 86                 )
 87             ),
 88             'stock'     => array(
 89                 'title'  => __( 'Stock', 'woocommerce' ),
 90                 'reports' => array(
 91                     "low_in_stock" => array(
 92                         'title'       => __( 'Low in stock', 'woocommerce' ),
 93                         'description' => '',
 94                         'hide_title'  => true,
 95                         'callback'    => array( __CLASS__, 'get_report' )
 96                     ),
 97                     "out_of_stock" => array(
 98                         'title'       => __( 'Out of stock', 'woocommerce' ),
 99                         'description' => '',
100                         'hide_title'  => true,
101                         'callback'    => array( __CLASS__, 'get_report' )
102                     ),
103                     "most_stocked" => array(
104                         'title'       => __( 'Most Stocked', 'woocommerce' ),
105                         'description' => '',
106                         'hide_title'  => true,
107                         'callback'    => array( __CLASS__, 'get_report' )
108                     ),
109                 )
110             )
111         );
112 
113         if ( get_option( 'woocommerce_calc_taxes' ) == 'yes' ) {
114             $reports['taxes'] = array(
115                 'title'  => __( 'Taxes', 'woocommerce' ),
116                 'reports' => array(
117                     "taxes_by_code" => array(
118                         'title'       => __( 'Taxes by code', 'woocommerce' ),
119                         'description' => '',
120                         'hide_title'  => true,
121                         'callback'    => array( __CLASS__, 'get_report' )
122                     ),
123                     "taxes_by_date" => array(
124                         'title'       => __( 'Taxes by date', 'woocommerce' ),
125                         'description' => '',
126                         'hide_title'  => true,
127                         'callback'    => array( __CLASS__, 'get_report' )
128                     ),
129                 )
130             );
131         }
132 
133         $reports = apply_filters( 'woocommerce_admin_reports', $reports );
134         $reports = apply_filters( 'woocommerce_reports_charts', $reports ); // Backwards compat
135 
136         foreach ( $reports as $key => $report_group ) {
137             if ( isset( $reports[ $key ]['charts'] ) ) {
138                 $reports[ $key ]['reports'] = $reports[ $key ]['charts'];
139             }
140 
141             foreach ( $reports[ $key ]['reports'] as $report_key => $report ) {
142                 if ( isset( $reports[ $key ]['reports'][ $report_key ]['function'] ) ) {
143                     $reports[ $key ]['reports'][ $report_key ]['callback'] = $reports[ $key ]['reports'][ $report_key ]['function'];
144                 }
145             }
146         }
147 
148         return $reports;
149     }
150 
151     /**
152      * Get a report from our reports subfolder
153      */
154     public static function get_report( $name ) {
155         $name  = sanitize_title( str_replace( '_', '-', $name ) );
156         $class = 'WC_Report_' . str_replace( '-', '_', $name );
157 
158         include_once( 'reports/class-wc-report-' . $name . '.php' );
159 
160         if ( ! class_exists( $class ) )
161             return;
162 
163         $report = new $class();
164         $report->output_report();
165     }
166 }
167 
168 endif;
WooCommerce API documentation generated by ApiGen 2.8.0