/** * Get the Export Data * * @access public * @since 1.5 * @global object $wpdb Used to query the database using the WordPress * Database API * @return array $data The data for the CSV file */ public function get_data() { if ($this->step == 1) { $this->delete_data('give_temp_recount_income'); } $total = get_option('give_temp_recount_income', false); if (false === $total) { $total = (double) 0; $this->store_data('give_temp_recount_income', $total); } $accepted_statuses = apply_filters('give_recount_accepted_statuses', array('publish')); $args = apply_filters('give_recount_income_args', array('number' => $this->per_step, 'page' => $this->step, 'status' => $accepted_statuses, 'fields' => 'ids')); $payments = give_get_payments($args); if (!empty($payments)) { foreach ($payments as $payment) { $total += give_get_payment_amount($payment); } if ($total < 0) { $totals = 0; } $total = round($total, give_currency_decimal_filter()); $this->store_data('give_temp_recount_income', $total); return true; } update_option('give_income_total', $total); set_transient('give_income_total', $total, 86400); return false; }
/** * Get the Export Data. * * @access public * @since 1.5 * @global object $wpdb Used to query the database using the WordPress database API. * @return array $data The data for the CSV file. */ public function get_data() { global $wpdb; $data = array(); $args = array('number' => 30, 'page' => $this->step, 'status' => $this->status); if (!empty($this->start) || !empty($this->end)) { $args['date_query'] = array(array('after' => date('Y-n-d 00:00:00', strtotime($this->start)), 'before' => date('Y-n-d 23:59:59', strtotime($this->end)), 'inclusive' => true)); } //echo json_encode($args ); exit; $payments = give_get_payments($args); if ($payments) { foreach ($payments as $payment) { $payment_meta = give_get_payment_meta($payment->ID); $user_info = give_get_payment_meta_user_info($payment->ID); $total = give_get_payment_amount($payment->ID); $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email']; $products = ''; $skus = ''; if (is_numeric($user_id)) { $user = get_userdata($user_id); } else { $user = false; } $data[] = array('id' => $payment->ID, 'seq_id' => give_get_payment_number($payment->ID), 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'address1' => isset($user_info['address']['line1']) ? $user_info['address']['line1'] : '', 'address2' => isset($user_info['address']['line2']) ? $user_info['address']['line2'] : '', 'city' => isset($user_info['address']['city']) ? $user_info['address']['city'] : '', 'state' => isset($user_info['address']['state']) ? $user_info['address']['state'] : '', 'country' => isset($user_info['address']['country']) ? $user_info['address']['country'] : '', 'zip' => isset($user_info['address']['zip']) ? $user_info['address']['zip'] : '', 'form_id' => isset($payment_meta['form_id']) ? $payment_meta['form_id'] : '', 'form_name' => isset($payment_meta['form_title']) ? $payment_meta['form_title'] : '', 'skus' => $skus, 'amount' => html_entity_decode(give_format_amount($total)), 'gateway' => give_get_gateway_admin_label(get_post_meta($payment->ID, '_give_payment_gateway', true)), 'trans_id' => give_get_payment_transaction_id($payment->ID), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'give'), 'status' => give_get_payment_status($payment, true)); } $data = apply_filters('give_export_get_data', $data); $data = apply_filters('give_export_get_data_' . $this->export_type, $data); return $data; } return false; }
/** * Get the Export Data * * @access public * @since 1.5 * @global object $wpdb Used to query the database using the WordPress * Database API * @return array $data The data for the CSV file */ public function get_data() { $args = array('number' => $this->per_step, 'offset' => $this->per_step * ($this->step - 1), 'orderby' => 'id', 'order' => 'DESC'); $customers = Give()->customers->get_customers($args); if ($customers) { $allowed_payment_status = apply_filters('give_recount_customer_payment_statuses', give_get_payment_status_keys()); foreach ($customers as $customer) { $attached_payment_ids = explode(',', $customer->payment_ids); $attached_args = array('post__in' => $attached_payment_ids, 'number' => -1, 'status' => $allowed_payment_status); $attached_payments = (array) give_get_payments($attached_args); $unattached_args = array('post__not_in' => $attached_payment_ids, 'number' => -1, 'status' => $allowed_payment_status, 'meta_query' => array(array('key' => '_give_payment_user_email', 'value' => $customer->email, 'compare' => '='))); $unattached_payments = give_get_payments($unattached_args); $payments = array_merge($attached_payments, $unattached_payments); $purchase_value = 0.0; $purchase_count = 0; $payment_ids = array(); if ($payments) { foreach ($payments as $payment) { $should_process_payment = 'publish' == $payment->post_status ? true : false; $should_process_payment = apply_filters('give_customer_recount_should_process_payment', $should_process_payment, $payment); if (true === $should_process_payment) { if (apply_filters('give_customer_recount_should_increase_value', true, $payment)) { $purchase_value += give_get_payment_amount($payment->ID); } if (apply_filters('give_customer_recount_should_increase_count', true, $payment)) { $purchase_count++; } } $payment_ids[] = $payment->ID; } } $payment_ids = implode(',', $payment_ids); $customer_update_data = array('purchase_count' => $purchase_count, 'purchase_value' => $purchase_value, 'payment_ids' => $payment_ids); $customer_instance = new Give_Customer($customer->id); $customer_instance->update($customer_update_data); } return true; } return false; }
/** * Get the Export Data * * @access public * @since 1.0 * @global object $wpdb Used to query the database using the WordPress * Database API * @return array $data The data for the CSV file */ public function get_data() { global $wpdb, $give_options; $data = array(); $payments = give_get_payments(array('offset' => 0, 'number' => -1, 'mode' => give_is_test_mode() ? 'test' : 'live', 'status' => isset($_POST['give_export_payment_status']) ? $_POST['give_export_payment_status'] : 'any', 'month' => isset($_POST['month']) ? absint($_POST['month']) : date('n'), 'year' => isset($_POST['year']) ? absint($_POST['year']) : date('Y'))); foreach ($payments as $payment) { $payment_meta = give_get_payment_meta($payment->ID); $user_info = give_get_payment_meta_user_info($payment->ID); $total = give_get_payment_amount($payment->ID); $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email']; $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : ''; $form_title = isset($payment_meta['form_title']) ? $payment_meta['form_title'] : ''; if (is_numeric($user_id)) { $user = get_userdata($user_id); } else { $user = false; } $data[] = array('id' => $payment->ID, 'seq_id' => give_get_payment_number($payment->ID), 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'address1' => isset($user_info['address']['line1']) ? $user_info['address']['line1'] : '', 'address2' => isset($user_info['address']['line2']) ? $user_info['address']['line2'] : '', 'city' => isset($user_info['address']['city']) ? $user_info['address']['city'] : '', 'state' => isset($user_info['address']['state']) ? $user_info['address']['state'] : '', 'country' => isset($user_info['address']['country']) ? $user_info['address']['country'] : '', 'zip' => isset($user_info['address']['zip']) ? $user_info['address']['zip'] : '', 'amount' => html_entity_decode(give_format_amount($total)), 'form_id' => $form_id, 'form' => $form_title, 'gateway' => give_get_gateway_admin_label(get_post_meta($payment->ID, '_give_payment_gateway', true)), 'trans_id' => give_get_payment_transaction_id($payment->ID), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'give'), 'status' => give_get_payment_status($payment, true)); } $data = apply_filters('give_export_get_data', $data); $data = apply_filters('give_export_get_data_' . $this->export_type, $data); return $data; }
/** * View a customer * * @since 1.0 * * @param $customer The Customer object being displayed * * @return void */ function give_customers_view($customer) { $customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments'); ?> <?php do_action('give_donor_card_top', $customer); ?> <div id="donor-summary" class="info-wrapper customer-section postbox"> <form id="edit-customer-info" method="post" action="<?php echo admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $customer->id); ?> "> <div class="customer-info"> <div class="donor-bio-header clearfix"> <div class="avatar-wrap left" id="customer-avatar"> <?php echo get_avatar($customer->email); ?> </div> <div class="customer-id" class="left"> #<?php echo $customer->id; ?> </div> <div id="customer-name-wrap" class="left"> <span class="customer-name info-item edit-item"><input size="15" data-key="name" name="customerinfo[name]" type="text" value="<?php echo esc_attr($customer->name); ?> " placeholder="<?php _e('Donor Name', 'give'); ?> " /></span> <span class="customer-name info-item editable"><span data-key="name"><?php echo $customer->name; ?> </span></span> </div> <p class="customer-since info-item"> <?php _e('Donor since', 'give'); ?> <?php echo date_i18n(get_option('date_format'), strtotime($customer->date_created)); ?> </p> <?php if (current_user_can($customer_edit_role)) { ?> <a title="<?php _e('Edit Donor', 'give'); ?> " href="#" id="edit-customer" class="button info-item editable customer-edit-link"><?php _e('Edit Donor', 'give'); ?> </a> <?php } ?> </div> <!-- /donor-bio-header --> <div class="customer-main-wrapper"> <table class="widefat"> <tbody> <tr> <td><label for="tablecell"><?php esc_attr_e('Email', 'give'); ?> </label></td> <td class="row-title"> <span class="customer-name info-item edit-item"><input size="20" data-key="email" name="customerinfo[email]" type="text" value="<?php echo $customer->email; ?> " placeholder="<?php _e('Donor Email', 'give'); ?> " /></span> <span class="customer-email info-item editable" data-key="email"><?php echo $customer->email; ?> </span> </td> </tr> <tr class="alternate"> <td><label for="tablecell"><?php esc_attr_e('User ID', 'give'); ?> </label></td> <td class="row-title"> <span class="customer-user-id info-item edit-item"> <?php $user_id = $customer->user_id > 0 ? $customer->user_id : ''; $data_atts = array('key' => 'user_login', 'exclude' => $user_id); $user_args = array('name' => 'customerinfo[user_login]', 'class' => 'give-user-dropdown', 'data' => $data_atts); if (!empty($user_id)) { $userdata = get_userdata($user_id); $user_args['value'] = $userdata->user_login; } echo Give()->html->ajax_user_search($user_args); ?> <input type="hidden" name="customerinfo[user_id]" data-key="user_id" value="<?php echo $customer->user_id; ?> " /> </span> <span class="customer-user-id info-item editable"> <?php if (intval($customer->user_id) > 0) { ?> <span data-key="user_id"><?php echo $customer->user_id; ?> </span> <?php } else { ?> <span data-key="user_id"><?php _e('none', 'give'); ?> </span> <?php } ?> <?php if (current_user_can($customer_edit_role) && intval($customer->user_id) > 0) { ?> <span class="disconnect-user"> - <a id="disconnect-customer" href="#disconnect" title="<?php _e('Disconnects the current user ID from this customer record', 'give'); ?> "><?php _e('Disconnect User', 'give'); ?> </a></span> <?php } ?> </span> </td> </tr> <tr> <td><?php esc_attr_e('Address', 'give'); ?> </td> <td class="row-title"> <div class="customer-address-wrapper"> <?php if (isset($customer->user_id) && $customer->user_id > 0) { ?> <?php $address = get_user_meta($customer->user_id, '_give_user_address', true); $defaults = array('line1' => '', 'line2' => '', 'city' => '', 'state' => '', 'country' => '', 'zip' => ''); $address = wp_parse_args($address, $defaults); ?> <?php if (!empty($address)) { ?> <span class="customer-address info-item editable"> <span class="info-item" data-key="line1"><?php echo $address['line1']; ?> </span><br> <span class="info-item" data-key="line2"><?php echo $address['line2']; ?> </span><br> <span class="info-item" data-key="city">City: <?php echo $address['city']; ?> </span><br> <span class="info-item" data-key="state">State: <?php echo $address['state']; ?> </span><br> <span class="info-item" data-key="country">Country: <?php echo $address['country']; ?> </span><br> <span class="info-item" data-key="zip">Zip: <?php echo $address['zip']; ?> </span><br> </span> <?php } ?> <span class="customer-address info-item edit-item"> <input class="info-item" type="text" data-key="line1" name="customerinfo[line1]" placeholder="<?php _e('Address 1', 'give'); ?> " value="<?php echo $address['line1']; ?> " /> <input class="info-item" type="text" data-key="line2" name="customerinfo[line2]" placeholder="<?php _e('Address 2', 'give'); ?> " value="<?php echo $address['line2']; ?> " /> <input class="info-item" type="text" data-key="city" name="customerinfo[city]" placeholder="<?php _e('City', 'give'); ?> " value="<?php echo $address['city']; ?> " /> <select data-key="country" name="customerinfo[country]" id="billing_country" class="billing_country give-select edit-item"> <?php $selected_country = $address['country']; $countries = give_get_country_list(); foreach ($countries as $country_code => $country) { echo '<option value="' . esc_attr($country_code) . '"' . selected($country_code, $selected_country, false) . '>' . $country . '</option>'; } ?> </select> <?php $selected_state = give_get_state(); $states = give_get_states($selected_country); $selected_state = isset($address['state']) ? $address['state'] : $selected_state; if (!empty($states)) { ?> <select data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-select info-item"> <?php foreach ($states as $state_code => $state) { echo '<option value="' . $state_code . '"' . selected($state_code, $selected_state, false) . '>' . $state . '</option>'; } ?> </select> <?php } else { ?> <input type="text" size="6" data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-input info-item" placeholder="<?php _e('State / Province', 'give'); ?> " /> <?php } ?> <input class="info-item" type="text" data-key="zip" name="customerinfo[zip]" placeholder="<?php _e('Postal', 'give'); ?> " value="<?php echo $address['zip']; ?> " /> </span> <?php } else { echo "none"; } ?> </div> </td> </tr> </tbody> </table> </div> </div> <span id="customer-edit-actions" class="edit-item"> <input type="hidden" data-key="id" name="customerinfo[id]" value="<?php echo $customer->id; ?> " /> <?php wp_nonce_field('edit-customer', '_wpnonce', false, true); ?> <input type="hidden" name="give_action" value="edit-customer" /> <input type="submit" id="give-edit-customer-save" class="button-secondary" value="<?php _e('Update Donor', 'give'); ?> " /> <a id="give-edit-customer-cancel" href="" class="delete"><?php _e('Cancel', 'give'); ?> </a> </span> </form> </div> <?php do_action('give_donor_before_stats', $customer); ?> <div id="customer-stats-wrapper" class="customer-section postbox clear"> <ul> <li> <a title="<?php _e('View All Purchases', 'give'); ?> " href="<?php echo admin_url('edit.php?post_type=give_forms&page=give-payment-history&user='******'%d Completed Donation', '%d Completed Donations', $customer->purchase_count, 'give'), $customer->purchase_count); ?> </a> </li> <li> <span class="dashicons dashicons-chart-area"></span> <?php echo give_currency_filter(give_format_amount($customer->purchase_value)); ?> <?php _e('Lifetime Donations', 'give'); ?> </li> <?php do_action('give_donor_stats_list', $customer); ?> </ul> </div> <?php do_action('give_donor_before_tables_wrapper', $customer); ?> <div id="customer-tables-wrapper" class="customer-section"> <?php do_action('give_donor_before_tables', $customer); ?> <h3><?php _e('Recent Donations', 'give'); ?> </h3> <?php $payment_ids = explode(',', $customer->payment_ids); $payments = give_get_payments(array('post__in' => $payment_ids)); $payments = array_slice($payments, 0, 10); ?> <table class="wp-list-table widefat striped payments"> <thead> <tr> <th><?php _e('ID', 'give'); ?> </th> <th><?php _e('Amount', 'give'); ?> </th> <th><?php _e('Date', 'give'); ?> </th> <th><?php _e('Status', 'give'); ?> </th> <th><?php _e('Actions', 'give'); ?> </th> </tr> </thead> <tbody> <?php if (!empty($payments)) { ?> <?php foreach ($payments as $payment) { ?> <tr> <td><?php echo $payment->ID; ?> </td> <td><?php echo give_payment_amount($payment->ID); ?> </td> <td><?php echo date_i18n(get_option('date_format'), strtotime($payment->post_date)); ?> </td> <td><?php echo give_get_payment_status($payment, true); ?> </td> <td> <a title="<?php _e('View Details for Donation', 'give'); echo ' ' . $payment->ID; ?> " href="<?php echo admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id=' . $payment->ID); ?> "> <?php _e('View Details', 'give'); ?> </a> <?php do_action('give_donor_recent_purchases_actions', $customer, $payment); ?> </td> </tr> <?php } ?> <?php } else { ?> <tr> <td colspan="5"><?php _e('No Donations Found', 'give'); ?> </td> </tr> <?php } ?> </tbody> </table> <h3><?php _e('Completed Donations', 'give'); ?> </h3> <?php $donations = give_get_users_completed_donations($customer->email); ?> <table class="wp-list-table widefat striped downloads"> <thead> <tr> <th><?php echo give_get_forms_label_singular(); ?> </th> <th width="120px"><?php _e('Actions', 'give'); ?> </th> </tr> </thead> <tbody> <?php if (!empty($donations)) { ?> <?php foreach ($donations as $donation) { ?> <tr> <td><?php echo $donation->post_title; ?> </td> <td> <a title="<?php echo esc_attr(sprintf(__('View %s', 'give'), $donation->post_title)); ?> " href="<?php echo esc_url(admin_url('post.php?action=edit&post=' . $donation->ID)); ?> "> <?php printf(__('View %s', 'give'), give_get_forms_label_singular()); ?> </a> </td> </tr> <?php } ?> <?php } else { ?> <tr> <td colspan="2"><?php _e('No Completed Donations Found', 'give'); ?> </td> </tr> <?php } ?> </tbody> </table> <?php do_action('give_donor_after_tables', $customer); ?> </div> <?php do_action('give_donor_card_bottom', $customer); ?> <?php }
/** * Retrieves Recent Sales * * @access public * @since 1.1 * @return array */ public function get_recent_donations() { global $wp_query; $sales = array(); if (!user_can($this->user_id, 'view_give_reports') && !$this->override) { return $sales; } if (isset($wp_query->query_vars['id'])) { $query = array(); $query[] = give_get_payment_by('id', $wp_query->query_vars['id']); } elseif (isset($wp_query->query_vars['purchasekey'])) { $query = array(); $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); } elseif (isset($wp_query->query_vars['email'])) { $query = give_get_payments(array('meta_key' => '_give_payment_user_email', 'meta_value' => $wp_query->query_vars['email'], 'number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish')); } else { $query = give_get_payments(array('number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish')); } if ($query) { $i = 0; foreach ($query as $payment) { $payment_meta = give_get_payment_meta($payment->ID); $user_info = give_get_payment_meta_user_info($payment->ID); $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; $sales['donations'][$i]['ID'] = give_get_payment_number($payment->ID); $sales['donations'][$i]['transaction_id'] = give_get_payment_transaction_id($payment->ID); $sales['donations'][$i]['key'] = give_get_payment_key($payment->ID); $sales['donations'][$i]['total'] = give_get_payment_amount($payment->ID); $sales['donations'][$i]['gateway'] = give_get_payment_gateway($payment->ID); $sales['donations'][$i]['name'] = $first_name . ' ' . $last_name; $sales['donations'][$i]['fname'] = $first_name; $sales['donations'][$i]['lname'] = $last_name; $sales['donations'][$i]['email'] = give_get_payment_user_email($payment->ID); $sales['donations'][$i]['date'] = $payment->post_date; $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; $sales['donations'][$i]['form']['id'] = $form_id; $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); $sales['donations'][$i]['form']['price'] = $price; if (give_has_variable_prices($form_id)) { if (isset($payment_meta['price_id'])) { $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); $sales['donations'][$i]['form']['price_name'] = $price_name; $sales['donations'][$i]['form']['price_id'] = $price_id; $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); } } //Add custom meta to API foreach ($payment_meta as $meta_key => $meta_value) { $exceptions = array('form_title', 'form_id', 'price_id', 'user_info', 'key', 'email', 'date'); //Don't clutter up results with dupes if (in_array($meta_key, $exceptions)) { continue; } $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; } $i++; } } return apply_filters('give_api_donations_endpoint', $sales); }
/** * Zero out the data on step one * * @access public * @since 1.5 * @return void */ public function pre_fetch() { if ($this->step === 1) { $allowed_payment_status = apply_filters('give_recount_customer_payment_statuses', give_get_payment_status_keys()); // Before we start, let's zero out the customer's data $customer = new Give_Customer($this->customer_id); $customer->update(array('purchase_value' => give_format_amount(0), 'purchase_count' => 0)); $attached_payment_ids = explode(',', $customer->payment_ids); $attached_args = array('post__in' => $attached_payment_ids, 'number' => -1, 'status' => $allowed_payment_status); $attached_payments = give_get_payments($attached_args); $unattached_args = array('post__not_in' => $attached_payment_ids, 'number' => -1, 'status' => $allowed_payment_status, 'meta_query' => array(array('key' => '_give_payment_user_email', 'value' => $customer->email))); $unattached_payments = give_get_payments($unattached_args); $payments = array_merge($attached_payments, $unattached_payments); $this->store_data('give_recount_customer_payments_' . $customer->id, $payments); } }
/** * Mark Abandoned Donations * * Updates over a week-old 'pending' donations to 'abandoned' status. * * @since 1.0 * * @return void */ function give_mark_abandoned_donations() { $args = array('status' => 'pending', 'number' => -1, 'output' => 'give_payments'); add_filter('posts_where', 'give_filter_where_older_than_week'); $payments = give_get_payments($args); remove_filter('posts_where', 'give_filter_where_older_than_week'); if ($payments) { /** * Filter payment gateways: Used to set payment gateways which can be skip while transferring pending payment to abandon. * * @since 1.6 * * @param array $skip_payment_gateways Array of payment gateways */ $skip_payment_gateways = apply_filters('give_mark_abandoned_donation_gateways', array('offline')); foreach ($payments as $payment) { $gateway = give_get_payment_gateway($payment); // Skip payment gateways. if (in_array($gateway, $skip_payment_gateways)) { continue; } $payment->status = 'abandoned'; $payment->save(); } } }
/** * Looks up purchases by email that match the registering user * * This is for users that purchased as a guest and then came * back and created an account. * * @access public * @since 1.0 * * @param $user_id INT - the new user's ID * * @return void */ function give_add_past_purchases_to_new_user($user_id) { $email = get_the_author_meta('user_email', $user_id); $payments = give_get_payments(array('s' => $email)); if ($payments) { foreach ($payments as $payment) { if (intval(give_get_payment_user_id($payment->ID)) > 0) { continue; } // This payment already associated with an account $meta = give_get_payment_meta($payment->ID); $meta['user_info'] = maybe_unserialize($meta['user_info']); $meta['user_info']['id'] = $user_id; $meta['user_info'] = $meta['user_info']; // Store the updated user ID in the payment meta give_update_payment_meta($payment->ID, '_give_payment_meta', $meta); give_update_payment_meta($payment->ID, '_give_payment_user_id', $user_id); } } }
/** * Get Total Earnings * * @since 1.0 * * @return float $total Total earnings */ function give_get_total_earnings() { $total = get_option('give_earnings_total', false); // If no total stored in DB, use old method of calculating total earnings if (false === $total) { global $wpdb; $total = get_transient('give_earnings_total'); if (false === $total) { $total = (double) 0; $args = apply_filters('give_get_total_earnings_args', array('offset' => 0, 'number' => -1, 'status' => array('publish'), 'fields' => 'ids')); $payments = give_get_payments($args); if ($payments) { /* * If performing a purchase, we need to skip the very last payment in the database, since it calls * give_increase_total_earnings() on completion, which results in duplicated earnings for the very * first purchase */ if (did_action('give_update_payment_status')) { array_pop($payments); } if (!empty($payments)) { $payments = implode(',', $payments); $total += $wpdb->get_var("SELECT SUM(meta_value) FROM {$wpdb->postmeta} WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})"); } } // Cache results for 1 day. This cache is cleared automatically when a payment is made set_transient('give_earnings_total', $total, 86400); // Store the total for the first time update_option('give_earnings_total', $total); } } if ($total < 0) { $total = 0; // Don't ever show negative earnings } return apply_filters('give_total_earnings', round($total, give_currency_decimal_filter())); }
/** * Updates week-old+ 'pending' orders to 'abandoned' * * @since 1.0 * @return void */ function give_mark_abandoned_donations() { $args = array('status' => 'pending', 'number' => -1, 'fields' => 'ids'); add_filter('posts_where', 'give_filter_where_older_than_week'); $payments = give_get_payments($args); remove_filter('posts_where', 'give_filter_where_older_than_week'); if ($payments) { foreach ($payments as $payment) { $gateway = give_get_payment_gateway($payment); //Skip offline gateway payments if ($gateway == 'offline') { continue; } //Non-offline get marked as 'abandoned' give_update_payment_status($payment, 'abandoned'); } } }
/** * Retrieves Recent Sales * * @access public * @since 1.1 * @return array */ public function get_recent_donations() { global $wp_query; $sales = array(); if (!user_can($this->user_id, 'view_give_reports') && !$this->override) { return $sales; } if (isset($wp_query->query_vars['id'])) { $query = array(); $query[] = give_get_payment_by('id', $wp_query->query_vars['id']); } elseif (isset($wp_query->query_vars['purchasekey'])) { $query = array(); $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); } elseif (isset($wp_query->query_vars['email'])) { $query = give_get_payments(array('meta_key' => '_give_payment_user_email', 'meta_value' => $wp_query->query_vars['email'], 'number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish')); } else { $query = give_get_payments(array('number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish')); } if ($query) { $i = 0; foreach ($query as $payment) { $payment_meta = give_get_payment_meta($payment->ID); $user_info = give_get_payment_meta_user_info($payment->ID); $sales['donations'][$i]['ID'] = give_get_payment_number($payment->ID); $sales['donations'][$i]['transaction_id'] = give_get_payment_transaction_id($payment->ID); $sales['donations'][$i]['key'] = give_get_payment_key($payment->ID); $sales['donations'][$i]['total'] = give_get_payment_amount($payment->ID); $sales['donations'][$i]['gateway'] = give_get_payment_gateway($payment->ID); $sales['donations'][$i]['email'] = give_get_payment_user_email($payment->ID); $sales['donations'][$i]['date'] = $payment->post_date; $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; $sales['donations'][$i]['form']['id'] = $form_id; $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); $sales['donations'][$i]['form']['price'] = $price; if (give_has_variable_prices($form_id)) { if (isset($payment_meta['price_id'])) { $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); $sales['donations'][$i]['form']['price_name'] = $price_name; $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); } } $i++; } } return $sales; }
/** * Updates week-old+ 'pending' orders to 'abandoned' * * @since 1.0 * @return void */ function give_mark_abandoned_orders() { $args = array('status' => 'pending', 'number' => -1, 'fields' => 'ids'); add_filter('posts_where', 'give_filter_where_older_than_week'); $payments = give_get_payments($args); remove_filter('posts_where', 'give_filter_where_older_than_week'); if ($payments) { foreach ($payments as $payment) { give_update_payment_status($payment, 'abandoned'); } } }