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( 'reports/class-wc-admin-report.php' ); 
  13. include_once( '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. 'customers' => array( 
  49. 'title' => __( 'Customers', 'woocommerce' ),  
  50. 'reports' => array( 
  51. "customers" => array( 
  52. 'title' => __( 'Customers vs. Guests', 'woocommerce' ),  
  53. 'description' => '',  
  54. 'hide_title' => true,  
  55. 'callback' => array( __CLASS__, 'get_report' ) 
  56. ),  
  57. "customer_list" => array( 
  58. 'title' => __( 'Customer List', 'woocommerce' ),  
  59. 'description' => '',  
  60. 'hide_title' => true,  
  61. 'callback' => array( __CLASS__, 'get_report' ) 
  62. ),  
  63. ),  
  64. 'stock' => array( 
  65. 'title' => __( 'Stock', 'woocommerce' ),  
  66. 'reports' => array( 
  67. "low_in_stock" => array( 
  68. 'title' => __( 'Low in stock', 'woocommerce' ),  
  69. 'description' => '',  
  70. 'hide_title' => true,  
  71. 'callback' => array( __CLASS__, 'get_report' ) 
  72. ),  
  73. "out_of_stock" => array( 
  74. 'title' => __( 'Out of stock', 'woocommerce' ),  
  75. 'description' => '',  
  76. 'hide_title' => true,  
  77. 'callback' => array( __CLASS__, 'get_report' ) 
  78. ),  
  79. "most_stocked" => array( 
  80. 'title' => __( 'Most Stocked', 'woocommerce' ),  
  81. 'description' => '',  
  82. 'hide_title' => true,  
  83. 'callback' => array( __CLASS__, 'get_report' ) 
  84. ),  
  85. ); 
  86.  
  87. if ( wc_tax_enabled() ) { 
  88. $reports['taxes'] = array( 
  89. 'title' => __( 'Taxes', 'woocommerce' ),  
  90. 'reports' => array( 
  91. "taxes_by_code" => array( 
  92. 'title' => __( 'Taxes by code', 'woocommerce' ),  
  93. 'description' => '',  
  94. 'hide_title' => true,  
  95. 'callback' => array( __CLASS__, 'get_report' ) 
  96. ),  
  97. "taxes_by_date" => array( 
  98. 'title' => __( 'Taxes by date', 'woocommerce' ),  
  99. 'description' => '',  
  100. 'hide_title' => true,  
  101. 'callback' => array( __CLASS__, 'get_report' ) 
  102. ),  
  103. ); 
  104.  
  105. $reports = apply_filters( 'woocommerce_admin_reports', $reports ); 
  106. $reports = apply_filters( 'woocommerce_reports_charts', $reports ); // Backwards compat 
  107.  
  108. foreach ( $reports as $key => $report_group ) { 
  109. if ( isset( $reports[ $key ]['charts'] ) ) { 
  110. $reports[ $key ]['reports'] = $reports[ $key ]['charts']; 
  111.  
  112. foreach ( $reports[ $key ]['reports'] as $report_key => $report ) { 
  113. if ( isset( $reports[ $key ]['reports'][ $report_key ]['function'] ) ) { 
  114. $reports[ $key ]['reports'][ $report_key ]['callback'] = $reports[ $key ]['reports'][ $report_key ]['function']; 
  115.  
  116. return $reports; 
  117.  
  118. /** 
  119. * Get a report from our reports subfolder. 
  120. */ 
  121. public static function get_report( $name ) { 
  122. $name = sanitize_title( str_replace( '_', '-', $name ) ); 
  123. $class = 'WC_Report_' . str_replace( '-', '_', $name ); 
  124.  
  125. include_once( apply_filters( 'wc_admin_reports_path', 'reports/class-wc-report-' . $name . '.php', $name, $class ) ); 
  126.  
  127. if ( ! class_exists( $class ) ) 
  128. return; 
  129.  
  130. $report = new $class(); 
  131. $report->output_report();