WC_REST_Report_Customers_Totals_Controller::get_reports()
Get reports list.
Method of the class: WC_REST_Report_Customers_Totals_Controller{}
No Hooks.
Return
Array
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_reports();
Changelog
Since 3.5.0 | Introduced. |
WC_REST_Report_Customers_Totals_Controller::get_reports() WC REST Report Customers Totals Controller::get reports code WC 7.7.0
protected function get_reports() { $users_count = count_users(); $total_customers = 0; foreach ( $users_count['avail_roles'] as $role => $total ) { if ( in_array( $role, array( 'administrator', 'shop_manager' ), true ) ) { continue; } $total_customers += (int) $total; } $customers_query = new WP_User_Query( array( 'role__not_in' => array( 'administrator', 'shop_manager' ), 'number' => 0, 'fields' => 'ID', 'count_total' => true, 'meta_query' => array( // WPCS: slow query ok. array( 'key' => 'paying_customer', 'value' => 1, 'compare' => '=', ), ), ) ); $total_paying = (int) $customers_query->get_total(); $data = array( array( 'slug' => 'paying', 'name' => __( 'Paying customer', 'woocommerce' ), 'total' => $total_paying, ), array( 'slug' => 'non_paying', 'name' => __( 'Non-paying customer', 'woocommerce' ), 'total' => $total_customers - $total_paying, ), ); return $data; }