You appear to be a bot. Output may be restricted
Description
Process Get Customers API Request
Usage
$array = EDD_API::get_customers( $customer );
Parameters
- $customer
- ( int ) optional – Customer ID
Returns
array $customers Multidimensional array of the customers
Source
File name: easy-digital-downloads/includes/api/class-edd-api.php
Lines:
1 to 93 of 93
public function get_customers( $customer = null ) { $customer = is_array( $customer ) ? $customer['customer'] : $customer; $customers = array(); $error = array(); if( ! user_can( $this->user_id, 'view_shop_sensitive_data' ) && ! $this->override ) { return $customers; } global $wpdb; $paged = $this->get_paged(); $per_page = $this->per_page(); $offset = $per_page * ( $paged - 1 ); if( is_numeric( $customer ) ) { $field = 'id'; } elseif ( is_array( $customer ) ) { // Checking if search is being done by id, email, user_id fields. if ( array_key_exists( 'id', $customer ) ) { $field = 'id'; } elseif ( array_key_exists( 'email', $customer ) ) { $field = 'email'; } elseif ( array_key_exists( 'user_id', $customer ) ) { $field = 'user_id'; } $customer = $customer[ $field ]; } else { $field = 'email'; } $customer_query = EDD()->customers->get_customers( array( 'number' => $per_page, 'offset' => $offset, $field => $customer ) ); $customer_count = 0; if( $customer_query ) { foreach ( $customer_query as $customer_obj ) { $names = explode( ' ', $customer_obj->name ); $first_name = ! empty( $names[0] ) ? $names[0] : ''; $last_name = ''; if( ! empty( $names[1] ) ) { unset( $names[0] ); $last_name = implode( ' ', $names ); } $customers['customers'][$customer_count]['info']['id'] = ''; $customers['customers'][$customer_count]['info']['user_id'] = ''; $customers['customers'][$customer_count]['info']['username'] = ''; $customers['customers'][$customer_count]['info']['display_name'] = ''; $customers['customers'][$customer_count]['info']['customer_id'] = $customer_obj->id; $customers['customers'][$customer_count]['info']['first_name'] = $first_name; $customers['customers'][$customer_count]['info']['last_name'] = $last_name; $customers['customers'][$customer_count]['info']['email'] = $customer_obj->email; if ( ! empty( $customer_obj->user_id ) && $customer_obj->user_id > 0 ) { $user_data = get_userdata( $customer_obj->user_id ); // Customer with registered account // id is going to get deprecated in the future, user user_id or customer_id instead $customers['customers'][$customer_count]['info']['id'] = $customer_obj->user_id; $customers['customers'][$customer_count]['info']['user_id'] = $customer_obj->user_id; $customers['customers'][$customer_count]['info']['username'] = $user_data->user_login; $customers['customers'][$customer_count]['info']['display_name'] = $user_data->display_name; } $customers['customers'][$customer_count]['stats']['total_purchases'] = $customer_obj->purchase_count; $customers['customers'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; $customers['customers'][$customer_count]['stats']['total_downloads'] = edd_count_file_downloads_of_customer( $customer_obj->id ); $customer_count++; } } elseif( $customer ) { $error['error'] = sprintf( __( 'Customer %s not found!', 'easy-digital-downloads' ), $customer ); return $error; } else { $error['error'] = __( 'No customers found!', 'easy-digital-downloads' ); return $error; } return apply_filters( 'edd_api_customers', $customers, $this ); }