Handle “all guests” when getting customers from orders.

This commit is contained in:
Jeff Stieler 2019-04-10 14:48:03 -06:00
parent 211c00935a
commit 071dc7debe
1 changed files with 11 additions and 6 deletions

View File

@ -337,23 +337,28 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
} }
/** /**
* Get customer data from order IDs. * Get customer data from Order data.
* *
* @param array $orders Array of orders. * @param array $orders Array of orders data.
* @return array * @return array
*/ */
protected function get_customers_by_orders( $orders ) { protected function get_customers_by_orders( $orders ) {
global $wpdb; global $wpdb;
$customer_lookup_table = $wpdb->prefix . 'wc_customer_lookup';
$customer_lookup_table = $wpdb->prefix . 'wc_customer_lookup';
$customer_ids = array(); $customer_ids = array();
foreach ( $orders as $order ) { foreach ( $orders as $order ) {
if ( $order['customer_id'] ) { if ( $order['customer_id'] ) {
$customer_ids[] = $order['customer_id']; $customer_ids[] = $order['customer_id'];
} }
} }
$customer_ids = implode( ',', $customer_ids );
if ( empty( $customer_ids ) ) {
return array();
}
$customer_ids = implode( ',', $customer_ids );
$customers = $wpdb->get_results( $customers = $wpdb->get_results(
"SELECT * FROM {$customer_lookup_table} WHERE customer_id IN ({$customer_ids})", "SELECT * FROM {$customer_lookup_table} WHERE customer_id IN ({$customer_ids})",
ARRAY_A ARRAY_A