/** * Calculates the total amount spent by a user * * @access public * @since 1.3 * @param $user mixed - ID or email * @return float - the total amount the user has spent */ function edd_purchase_total_of_user($user = null) { global $wpdb; $mode = edd_is_test_mode() ? 'test' : 'live'; $stats = edd_get_purchase_stats_by_user($user, $mode); return $stats['total_spent']; }
/** * Get the Export Data * * @access public * @since 1.4.4 * @global object $wpdb Used to query the database using the WordPress * Database API * @global object $edd_logs EDD Logs Object * @return array $data The data for the CSV file */ public function get_data() { global $wpdb; $data = array(); if (!empty($_POST['edd_export_download'])) { // Export customers of a specific product global $edd_logs; $args = array('post_parent' => absint($_POST['edd_export_download']), 'log_type' => 'sale', 'nopaging' => true); $logs = $edd_logs->get_connected_logs($args); if ($logs) { foreach ($logs as $log) { $payment_id = get_post_meta($log->ID, '_edd_log_payment_id', true); $email = edd_get_payment_user_email($payment_id); $wp_user = get_user_by('email', $email); $data[] = array('name' => $wp_user ? $wp_user->display_name : __('Guest', 'edd'), 'email' => $email, 'date' => $log->post_date); } } } else { // Export all customers $emails = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_edd_payment_user_email' "); $i = 0; foreach ($emails as $email) { if ('emails' != $_POST['edd_export_option']) { $wp_user = get_user_by('email', $email); $data[$i]['name'] = $wp_user ? $wp_user->display_name : __('Guest', 'edd'); } $data[$i]['email'] = $email; if ('full' == $_POST['edd_export_option']) { $stats = edd_get_purchase_stats_by_user($email); $data[$i]['purchases'] = $stats['purchases']; $data[$i]['amount'] = edd_format_amount($stats['total_spent']); } $i++; } } $data = apply_filters('edd_export_get_data', $data); $data = apply_filters('edd_export_get_data_' . $this->export_type, $data); return $data; }
/** * Calculates the total amount spent by a user * * @access public * @since 1.3 * @param $user mixed - ID or email * @return float - the total amount the user has spent */ function edd_purchase_total_of_user($user = null) { $stats = edd_get_purchase_stats_by_user($user); return $stats['total_spent']; }
/** * Build all the reports data * * @access public * @since 1.5 * @global object $wpdb Used to query the database using the WordPress * Database API * @return array $reports_data All the data for customer reports */ public function reports_data() { global $wpdb; $reports_data = array(); $paged = $this->get_paged(); $offset = $this->per_page * ($paged - 1); $customers = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_edd_payment_user_email' ORDER BY meta_id DESC LIMIT {$this->per_page} OFFSET {$offset}"); if ($customers) { foreach ($customers as $customer_email) { $wp_user = get_user_by('email', $customer_email); $user_id = $wp_user ? $wp_user->ID : 0; $mode = edd_is_test_mode() ? 'test' : 'live'; $stats = edd_get_purchase_stats_by_user($customer_email, $mode); $reports_data[] = array('ID' => $user_id, 'name' => $wp_user ? $wp_user->display_name : __('Guest', 'edd'), 'email' => $customer_email, 'num_purchases' => $stats['purchases'], 'amount_spent' => $stats['total_spent'], 'file_downloads' => edd_count_file_downloads_of_user(!empty($user_id) ? $user_id : $customer_email)); } } return $reports_data; }