/** * Retrieve sale stats * * @access public * @since 1.8 * @param INT $download_id The download product to retrieve stats for. If false, gets stats for all products * @param string|bool $start_date The starting date for which we'd like to filter our sale stats. If false, we'll use the default start date of `this_month` * @param string|bool $end_date The end date for which we'd like to filter our sale stats. If false, we'll use the default end date of `this_month` * @param string|array $status The sale status(es) to count. Only valid when retrieving global stats * @return float|int Total amount of sales based on the passed arguments. */ public function get_sales($download_id = 0, $start_date = false, $end_date = false, $status = 'publish') { $this->setup_dates($start_date, $end_date); // Make sure start date is valid if (is_wp_error($this->start_date)) { return $this->start_date; } // Make sure end date is valid if (is_wp_error($this->end_date)) { return $this->end_date; } if (empty($download_id)) { // Global sale stats add_filter('edd_count_payments_where', array($this, 'count_where')); if (is_array($status)) { $count = 0; foreach ($status as $payment_status) { $count += edd_count_payments()->{$payment_status}; } } else { $count = edd_count_payments()->{$status}; } remove_filter('edd_count_payments_where', array($this, 'count_where')); } else { $this->timestamp = false; // Product specific stats global $edd_logs; add_filter('posts_where', array($this, 'payments_where')); $count = $edd_logs->get_log_count($download_id, 'sale'); remove_filter('posts_where', array($this, 'payments_where')); } return $count; }
/** * Return the calculated completion percentage * * @since 2.5.3 * @return int */ public function get_percentage_complete() { $status = 'publish'; $args = array('start-date' => date('Y-n-d H:i:s', strtotime($this->start)), 'end-date' => date('Y-n-d H:i:s', strtotime($this->end))); $total = edd_count_payments($args)->{$status}; $percentage = 100; if ($total > 0) { $percentage = 30 * $this->step / $total * 100; } if ($percentage > 100) { $percentage = 100; } return $percentage; }
/** * Retrieve the payment counts * * @access public * @since 1.4 * @return void */ public function get_payment_counts() { global $wp_query; $args = array(); if (isset($_GET['user'])) { $args['user'] = urldecode($_GET['user']); } elseif (isset($_GET['customer'])) { $args['customer'] = absint($_GET['customer']); } elseif (isset($_GET['s'])) { $is_user = strpos($_GET['s'], strtolower('user:'******'user'] = absint(trim(str_replace('user:'******'', strtolower($_GET['s'])))); unset($args['s']); } else { $args['s'] = sanitize_text_field($_GET['s']); } } if (!empty($_GET['start-date'])) { $args['start-date'] = urldecode($_GET['start-date']); } if (!empty($_GET['end-date'])) { $args['end-date'] = urldecode($_GET['end-date']); } $payment_count = edd_count_payments($args); $this->complete_count = $payment_count->publish; $this->pending_count = $payment_count->pending; $this->refunded_count = $payment_count->refunded; $this->failed_count = $payment_count->failed; $this->revoked_count = $payment_count->revoked; $this->abandoned_count = $payment_count->abandoned; foreach ($payment_count as $count) { $this->total_count += $count; } }
/** * Return the calculated completion percentage * * @since 2.4 * @return int */ public function get_percentage_complete() { $status = $this->status; $args = array('start-date' => date('Y-n-d H:i:s', strtotime($this->start)), 'end-date' => date('Y-n-d H:i:s', strtotime($this->end))); if ('any' == $status) { $total = array_sum((array) edd_count_payments($args)); } else { $total = edd_count_payments($args)->{$status}; } $percentage = 100; if ($total > 0) { $percentage = 30 * $this->step / $total * 100; } if ($percentage > 100) { $percentage = 100; } return $percentage; }
/** * Get Total Sales * * @since 1.2.2 * @return int $count Total sales */ function edd_get_total_sales() { $payments = edd_count_payments(); return $payments->revoked + $payments->publish; }
/** * Remove sale logs from refunded orders * * @since 2.4.3 * @return void */ function edd_remove_refunded_sale_logs() { global $wpdb, $edd_logs; if (!current_user_can('manage_shop_settings')) { wp_die(__('You do not have permission to do shop upgrades', 'edd'), __('Error', 'edd'), array('response' => 403)); } ignore_user_abort(true); if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) { @set_time_limit(0); } $step = isset($_GET['step']) ? absint($_GET['step']) : 1; $total = isset($_GET['total']) ? absint($_GET['total']) : edd_count_payments()->refunded; $refunds = edd_get_payments(array('status' => 'refunded', 'number' => 20, 'page' => $step)); if (!empty($refunds)) { // Refunded Payments found so process them foreach ($refunds as $refund) { if ('refunded' !== $refund->post_status) { continue; // Just to be safe } // Remove related sale log entries $edd_logs->delete_logs(null, 'sale', array(array('key' => '_edd_log_payment_id', 'value' => $refund->ID))); } $step++; $redirect = add_query_arg(array('page' => 'edd-upgrades', 'edd-upgrade' => 'remove_refunded_sale_logs', 'step' => $step, 'total' => $total), admin_url('index.php')); wp_redirect($redirect); exit; } else { // No more refunded payments found, finish up update_option('edd_version', preg_replace('/[^0-9.].*/', '', EDD_VERSION)); edd_set_upgrade_complete('remove_refunded_sale_logs'); delete_option('edd_doing_upgrade'); wp_redirect(admin_url()); exit; } }
/** * Retrieve the payment counts * * @access public * @since 1.4 * @return void */ public function get_payment_counts() { global $wp_query; $args = array(); if (isset($_GET['user'])) { $args['user'] = urldecode($_GET['user']); } elseif (isset($_GET['s'])) { $args['s'] = urldecode($_GET['s']); } if (!empty($_GET['start-date'])) { $args['start-date'] = urldecode($_GET['start-date']); } if (!empty($_GET['end-date'])) { $args['end-date'] = urldecode($_GET['end-date']); } $payment_count = edd_count_payments($args); $this->complete_count = $payment_count->publish; $this->pending_count = $payment_count->pending; $this->refunded_count = $payment_count->refunded; $this->failed_count = $payment_count->failed; $this->revoked_count = $payment_count->revoked; $this->abandoned_count = $payment_count->abandoned; foreach ($payment_count as $count) { $this->total_count += $count; } }
/** * Upgrades for EDD v2.0 and sequential payment numbers * * @since 2.0 * @return void */ function edd_v20_upgrade_sequential_payment_numbers() { if (!current_user_can('manage_shop_settings')) { wp_die(__('You do not have permission to do shop upgrades', 'edd'), __('Error', 'edd'), array('response' => 403)); } ignore_user_abort(true); if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) { set_time_limit(0); } $step = isset($_GET['step']) ? absint($_GET['step']) : 1; $total = isset($_GET['total']) ? absint($_GET['total']) : false; if (empty($total) || $total <= 1) { $payments = edd_count_payments(); foreach ($payments as $status) { $total += $status; } } $args = array('number' => 100, 'page' => $step, 'status' => 'any', 'order' => 'ASC'); $payments = new EDD_Payments_Query($args); $payments = $payments->get_payments(); if ($payments) { $prefix = edd_get_option('sequential_prefix'); $postfix = edd_get_option('sequential_postfix'); $number = !empty($_GET['custom']) ? absint($_GET['custom']) : intval(edd_get_option('sequential_start', 1)); foreach ($payments as $payment) { // Re-add the prefix and postfix $payment_number = $prefix . $number . $postfix; edd_update_payment_meta($payment->ID, '_edd_payment_number', $payment_number); // Increment the payment number $number++; } // Payments found so upgrade them $step++; $redirect = add_query_arg(array('page' => 'edd-upgrades', 'edd-upgrade' => 'upgrade_sequential_payment_numbers', 'step' => $step, 'custom' => $number, 'total' => $total), admin_url('index.php')); wp_redirect($redirect); exit; } else { // No more payments found, finish up EDD()->session->set('upgrade_sequential', null); delete_option('edd_doing_upgrade'); wp_redirect(admin_url()); exit; } }
/** * Return the calculated completion percentage * * @since 2.5 * @return int */ public function get_percentage_complete() { $total = $this->get_stored_data('edd_recount_earnings_total'); if (false === $total) { $args = apply_filters('edd_recount_earnings_total_args', array()); $counts = edd_count_payments($args); $total = absint($counts->publish) + absint($counts->revoked); $total = apply_filters('edd_recount_store_earnings_total', $total); $this->store_data('edd_recount_earnings_total', $total); } $percentage = 100; if ($total > 0) { $percentage = $this->per_step * $this->step / $total * 100; } if ($percentage > 100) { $percentage = 100; } return $percentage; }