diff --git a/plugins/woocommerce-admin/client/analytics/report/customers/table.js b/plugins/woocommerce-admin/client/analytics/report/customers/table.js index 497cdb53631..3d58782d0cd 100644 --- a/plugins/woocommerce-admin/client/analytics/report/customers/table.js +++ b/plugins/woocommerce-admin/client/analytics/report/customers/table.js @@ -25,6 +25,7 @@ export default class CustomersReportTable extends Component { this.getHeadersContent = this.getHeadersContent.bind( this ); this.getRowsContent = this.getRowsContent.bind( this ); + this.getSummary = this.getSummary.bind( this ); } getHeadersContent() { @@ -187,6 +188,30 @@ export default class CustomersReportTable extends Component { } ); } + getSummary( totals ) { + if ( ! totals ) { + return []; + } + return [ + { + label: __( 'customers', 'wc-admin' ), + value: numberFormat( totals.customers_count ), + }, + { + label: __( 'average orders', 'wc-admin' ), + value: numberFormat( totals.avg_orders_count ), + }, + { + label: __( 'average lifetime spend', 'wc-admin' ), + value: formatCurrency( totals.avg_total_spend ), + }, + { + label: __( 'average order value', 'wc-admin' ), + value: formatCurrency( totals.avg_avg_order_value ), + }, + ]; + } + render() { const { query } = this.props; @@ -195,6 +220,7 @@ export default class CustomersReportTable extends Component { endpoint="customers" getHeadersContent={ this.getHeadersContent } getRowsContent={ this.getRowsContent } + getSummary={ this.getSummary } itemIdField="id" query={ query } labels={ { placeholder: __( 'Search by customer name', 'wc-admin' ) } } diff --git a/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js b/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js index 5d0d8876be3..97193986cd9 100644 --- a/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js +++ b/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js @@ -16,7 +16,15 @@ import { getResourceIdentifier, getResourcePrefix } from '../../utils'; import { NAMESPACE } from '../../constants'; import { SWAGGERNAMESPACE } from 'store/constants'; -const statEndpoints = [ 'coupons', 'downloads', 'orders', 'products', 'revenue', 'taxes' ]; +const statEndpoints = [ + 'coupons', + 'downloads', + 'orders', + 'products', + 'revenue', + 'taxes', + 'customers', +]; // TODO: Remove once swagger endpoints are phased out. const swaggerEndpoints = [ 'categories' ]; @@ -28,6 +36,7 @@ const typeEndpointMap = { 'report-stats-query-downloads': 'downloads', 'report-stats-query-coupons': 'coupons', 'report-stats-query-taxes': 'taxes', + 'report-stats-query-customers': 'customers', }; function read( resourceNames, fetch = apiFetch ) { diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-customers-stats-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-customers-stats-controller.php index bd28daa23f8..af24ea6119d 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-customers-stats-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-customers-stats-controller.php @@ -75,7 +75,8 @@ class WC_Admin_REST_Reports_Customers_Stats_Controller extends WC_REST_Reports_C $report_data = $customers_query->get_data(); $out_data = array( 'totals' => $report_data, - 'intervals' => array(), // TODO: is this needed? + // TODO: is this needed? the single element array tricks the isReportDataEmpty() selector. + 'intervals' => array( (object) array() ), ); return rest_ensure_response( $out_data );