WC_Admin_Reports

WC_Admin_Reports Class.

Defined (1)

The class is defined in the following location(s).

/includes/admin/class-wc-admin-reports.php  
  1. class WC_Admin_Reports { 
  2.  
  3. /** 
  4. * Handles output of the reports page in admin. 
  5. */ 
  6. public static function output() { 
  7. $reports = self::get_reports(); 
  8. $first_tab = array_keys( $reports ); 
  9. $current_tab = ! empty( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : $first_tab[0]; 
  10. $current_report = isset( $_GET['report'] ) ? sanitize_title( $_GET['report'] ) : current( array_keys( $reports[ $current_tab ]['reports'] ) ); 
  11.  
  12. include_once( dirname( __FILE__ ) . '/reports/class-wc-admin-report.php' ); 
  13. include_once( dirname( __FILE__ ) . '/views/html-admin-page-reports.php' ); 
  14.  
  15. /** 
  16. * Returns the definitions for the reports to show in admin. 
  17. * @return array 
  18. */ 
  19. public static function get_reports() { 
  20. $reports = array( 
  21. 'orders' => array( 
  22. 'title' => __( 'Orders', 'woocommerce' ),  
  23. 'reports' => array( 
  24. "sales_by_date" => array( 
  25. 'title' => __( 'Sales by date', 'woocommerce' ),  
  26. 'description' => '',  
  27. 'hide_title' => true,  
  28. 'callback' => array( __CLASS__, 'get_report' ),  
  29. ),  
  30. "sales_by_product" => array( 
  31. 'title' => __( 'Sales by product', 'woocommerce' ),  
  32. 'description' => '',  
  33. 'hide_title' => true,  
  34. 'callback' => array( __CLASS__, 'get_report' ),  
  35. ),  
  36. "sales_by_category" => array( 
  37. 'title' => __( 'Sales by category', 'woocommerce' ),  
  38. 'description' => '',  
  39. 'hide_title' => true,  
  40. 'callback' => array( __CLASS__, 'get_report' ),  
  41. ),  
  42. "coupon_usage" => array( 
  43. 'title' => __( 'Coupons by date', 'woocommerce' ),  
  44. 'description' => '',  
  45. 'hide_title' => true,  
  46. 'callback' => array( __CLASS__, 'get_report' ),  
  47. ),  
  48. ),  
  49. ),  
  50. 'customers' => array( 
  51. 'title' => __( 'Customers', 'woocommerce' ),  
  52. 'reports' => array( 
  53. "customers" => array( 
  54. 'title' => __( 'Customers vs. guests', 'woocommerce' ),  
  55. 'description' => '',  
  56. 'hide_title' => true,  
  57. 'callback' => array( __CLASS__, 'get_report' ),  
  58. ),  
  59. "customer_list" => array( 
  60. 'title' => __( 'Customer list', 'woocommerce' ),  
  61. 'description' => '',  
  62. 'hide_title' => true,  
  63. 'callback' => array( __CLASS__, 'get_report' ),  
  64. ),  
  65. ),  
  66. ),  
  67. 'stock' => array( 
  68. 'title' => __( 'Stock', 'woocommerce' ),  
  69. 'reports' => array( 
  70. "low_in_stock" => array( 
  71. 'title' => __( 'Low in stock', 'woocommerce' ),  
  72. 'description' => '',  
  73. 'hide_title' => true,  
  74. 'callback' => array( __CLASS__, 'get_report' ),  
  75. ),  
  76. "out_of_stock" => array( 
  77. 'title' => __( 'Out of stock', 'woocommerce' ),  
  78. 'description' => '',  
  79. 'hide_title' => true,  
  80. 'callback' => array( __CLASS__, 'get_report' ),  
  81. ),  
  82. "most_stocked" => array( 
  83. 'title' => __( 'Most Stocked', 'woocommerce' ),  
  84. 'description' => '',  
  85. 'hide_title' => true,  
  86. 'callback' => array( __CLASS__, 'get_report' ),  
  87. ),  
  88. ),  
  89. ),  
  90. ); 
  91.  
  92. if ( wc_tax_enabled() ) { 
  93. $reports['taxes'] = array( 
  94. 'title' => __( 'Taxes', 'woocommerce' ),  
  95. 'reports' => array( 
  96. "taxes_by_code" => array( 
  97. 'title' => __( 'Taxes by code', 'woocommerce' ),  
  98. 'description' => '',  
  99. 'hide_title' => true,  
  100. 'callback' => array( __CLASS__, 'get_report' ),  
  101. ),  
  102. "taxes_by_date" => array( 
  103. 'title' => __( 'Taxes by date', 'woocommerce' ),  
  104. 'description' => '',  
  105. 'hide_title' => true,  
  106. 'callback' => array( __CLASS__, 'get_report' ),  
  107. ),  
  108. ),  
  109. ); 
  110.  
  111. $reports = apply_filters( 'woocommerce_admin_reports', $reports ); 
  112. $reports = apply_filters( 'woocommerce_reports_charts', $reports ); // Backwards compat 
  113.  
  114. foreach ( $reports as $key => $report_group ) { 
  115. if ( isset( $reports[ $key ]['charts'] ) ) { 
  116. $reports[ $key ]['reports'] = $reports[ $key ]['charts']; 
  117.  
  118. foreach ( $reports[ $key ]['reports'] as $report_key => $report ) { 
  119. if ( isset( $reports[ $key ]['reports'][ $report_key ]['function'] ) ) { 
  120. $reports[ $key ]['reports'][ $report_key ]['callback'] = $reports[ $key ]['reports'][ $report_key ]['function']; 
  121.  
  122. return $reports; 
  123.  
  124. /** 
  125. * Get a report from our reports subfolder. 
  126. */ 
  127. public static function get_report( $name ) { 
  128. $name = sanitize_title( str_replace( '_', '-', $name ) ); 
  129. $class = 'WC_Report_' . str_replace( '-', '_', $name ); 
  130.  
  131. include_once( apply_filters( 'wc_admin_reports_path', 'reports/class-wc-report-' . $name . '.php', $name, $class ) ); 
  132.  
  133. if ( ! class_exists( $class ) ) 
  134. return; 
  135.  
  136. $report = new $class(); 
  137. $report->output_report();