/** * Get the data being exported * * @access public * @since 1.2 * @return array */ public function get_data() { global $edd_logs; $data = array(); $args = array('nopaging' => true, 'post_type' => 'edd_payment', 'meta_key' => '_edd_payment_shipping_status', 'meta_value' => '1', 'fields' => 'ids'); $payments = get_posts($args); if ($payments) { foreach ($payments as $payment) { $user_info = edd_get_payment_meta_user_info($payment); $downloads = edd_get_payment_meta_cart_details($payment); $products = ''; if ($downloads) { foreach ($downloads as $key => $download) { // Display the Downoad Name $products .= get_the_title($download['id']); if ($key != count($downloads) - 1) { $products .= ' / '; } } } $data[] = array('id' => $payment, 'date' => get_post_field('post_date', $payment), 'first_name' => $user_info['first_name'], 'last_name' => $user_info['last_name'], 'email' => $user_info['email'], 'address' => $user_info['shipping_info']['address'], 'address2' => !empty($user_info['shipping_info']['address2']) ? $user_info['shipping_info']['address2'] : '', 'city' => $user_info['shipping_info']['city'], 'state' => $user_info['shipping_info']['state'], 'zip' => $user_info['shipping_info']['zip'], 'country' => $user_info['shipping_info']['country'], 'amount' => edd_get_payment_amount($payment), 'tax' => edd_get_payment_tax($payment), 'gateway' => edd_get_payment_gateway($payment), 'key' => edd_get_payment_key($payment), 'products' => $products, 'status' => get_post_field('post_status', $payment)); } } $data = apply_filters('edd_export_get_data', $data); $data = apply_filters('edd_export_get_data_' . $this->export_type, $data); return $data; }
/** * Get the Export Data * * @access public * @since 2.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() { $customer = new EDD_Customer($this->customer_id); $payments = $this->get_stored_data('edd_recount_customer_payments_' . $customer->id, array()); $offset = ($this->step - 1) * $this->per_step; $step_items = array_slice($payments, $offset, $this->per_step); if (count($step_items) > 0) { $pending_total = (double) $this->get_stored_data('edd_stats_customer_pending_total' . $customer->id, 0); $step_total = 0; $found_payment_ids = $this->get_stored_data('edd_stats_found_payments_' . $customer->id, array()); foreach ($step_items as $payment) { $payment = get_post($payment->ID); if (is_null($payment) || is_wp_error($payment) || 'edd_payment' !== $payment->post_type) { $missing_payments = $this->get_stored_data('edd_stats_missing_payments' . $customer->id, array()); $missing_payments[] = $payment->ID; $this->store_data('edd_stats_missing_payments' . $customer->id, $missing_payments); continue; } if ('publish' == $payment->post_status || 'revoked' == $payment->post_status) { $found_payment_ids[] = $payment->ID; $payment_amount = edd_get_payment_amount($payment->ID); $step_total += $payment_amount; } } $updated_total = $pending_total + $step_total; $this->store_data('edd_stats_customer_pending_total' . $customer->id, $updated_total); $this->store_data('edd_stats_found_payments_' . $customer->id, $found_payment_ids); return true; } return false; }
/** * Get the Export Data * * @access public * @since 2.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 = EDD()->customers->get_customers($args); if ($customers) { foreach ($customers as $customer) { $attached_payment_ids = explode(',', $customer->payment_ids); $attached_args = array('post__in' => $attached_payment_ids, 'number' => -1); $attached_payments = edd_get_payments($attached_args); $unattached_args = array('post__not_in' => $attached_payment_ids, 'number' => -1, 'meta_query' => array(array('key' => '_edd_payment_user_email', 'value' => $customer->email, 'compare' => '='))); $unattached_payments = edd_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) { if ('publish' == $payment->post_status || 'revoked' == $payment->post_status) { $purchase_value += edd_get_payment_amount($payment->ID); $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 EDD_Customer($customer->id); $customer_instance->update($customer_update_data); } return true; } return false; }
/** * Get the Export Data * * @access public * @since 2.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('edd_temp_recount_earnings'); } $total = get_option('edd_temp_recount_earnings', false); if (false === $total) { $total = (double) 0; $this->store_data('edd_temp_recount_earnings', $total); } $accepted_statuses = apply_filters('edd_recount_accepted_statuses', array('publish', 'revoked')); $args = apply_filters('edd_recount_earnings_args', array('number' => $this->per_step, 'page' => $this->step, 'status' => $accepted_statuses, 'fields' => 'ids')); $payments = edd_get_payments($args); if (!empty($payments)) { foreach ($payments as $payment) { $total += edd_get_payment_amount($payment); } if ($total < 0) { $totals = 0; } $total = round($total, edd_currency_decimal_filter()); $this->store_data('edd_temp_recount_earnings', $total); return true; } update_option('edd_earnings_total', $total); set_transient('edd_earnings_total', $total, 86400); return false; }
/** * Plugin Name: Easy Digital Downloads - Disable emails on free purchases */ function jp_no_email_free($payment_id) { $amount = edd_get_payment_amount($payment_id); if (0 == $amount) { remove_action('edd_complete_purchase', 'edd_trigger_purchase_receipt', 999, 1); // This disables customer purchase receipts remove_action('edd_admin_sale_notice', 'edd_admin_email_notice', 10, 2); // This disables email notices to admins } }
/** * Create identity and track purchase * @param int $payment_id * @return null */ public static function track_purchase($payment_id) { $user_id = edd_get_payment_user_id($payment_id); $uid = EDD_Segment_Identity::get_uid_from_user_id($user_id); // Send identity $traits = array('name' => edd_email_tag_fullname($payment_id), 'email' => edd_get_payment_user_email($payment_id)); do_action('edd_segment_identify', $uid, $traits); // Track the purchase event $props = array('trans_id' => edd_get_payment_transaction_id($payment_id), 'total' => edd_get_payment_amount($payment_id), 'time' => strtotime(edd_get_payment_completed_date($payment_id))); do_action('edd_segment_track', $uid, 'Checkout', $props); }
/** * Returns the admin label for the specified gateway * * @since 1.0.8.3 * @param string $gateway Name of the gateway to retrieve a label for * @return string Gateway admin label */ function edd_get_gateway_admin_label($gateway) { $gateways = edd_get_enabled_payment_gateways(); $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; $payment = isset($_GET['id']) ? absint($_GET['id']) : false; if ($gateway == 'manual' && $payment) { if (edd_get_payment_amount($payment) == 0) { $label = __('Free Purchase', 'edd'); } } return apply_filters('edd_gateway_admin_label', $label, $gateway); }
/** * Get the data being exported * * @return array $data */ public function get_data() { global $wpdb; $data = array(); $campaign = $this->campaign; $campaign = atcf_get_campaign($campaign); $backers = $campaign->backers(); if (empty($backers)) { return $data; } foreach ($backers as $log) { $payment_id = get_post_meta($log->ID, '_edd_log_payment_id', true); $payment = get_post($payment_id); $payment_meta = edd_get_payment_meta($payment_id); $user_info = edd_get_payment_meta_user_info($payment_id); $downloads = edd_get_payment_meta_cart_details($payment_id); $total = edd_get_payment_amount($payment_id); $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email']; $products = ''; if ($downloads) { foreach ($downloads as $key => $download) { // Download ID $id = isset($payment_meta['cart_details']) ? $download['id'] : $download; // If the download has variable prices, override the default price $price_override = isset($payment_meta['cart_details']) ? $download['price'] : null; $price = edd_get_download_final_price($id, $user_info, $price_override); // Display the Downoad Name $products .= get_the_title($id) . ' - '; if (isset($downloads[$key]['item_number'])) { $price_options = $downloads[$key]['item_number']['options']; if (isset($price_options['price_id'])) { $products .= edd_get_price_option_name($id, $price_options['price_id']) . ' - '; } } $products .= html_entity_decode(edd_currency_filter($price)); if ($key != count($downloads) - 1) { $products .= ' / '; } } } if (is_numeric($user_id)) { $user = get_userdata($user_id); } else { $user = false; } $shipping = isset($payment_meta['shipping']) ? $payment_meta['shipping'] : null; $data[] = apply_filters('atcf_csv_cols_values', array('id' => $payment_id, 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'shipping' => isset($shipping) ? implode("\n", $shipping) : '', 'products' => $products, 'amount' => html_entity_decode(edd_currency_filter(edd_format_amount($total))), 'tax' => html_entity_decode(edd_payment_tax($payment_id, $payment_meta)), 'discount' => isset($user_info['discount']) && $user_info['discount'] != 'none' ? $user_info['discount'] : __('none', 'atcf'), 'gateway' => edd_get_gateway_admin_label(get_post_meta($payment_id, '_edd_payment_gateway', true)), 'key' => $payment_meta['key'], 'date' => date_i18n(get_option('date_format'), strtotime($payment->post_date)), 'user' => $user ? $user->display_name : __('guest', 'atcf'), 'status' => edd_get_payment_status($payment, true)), $payment_id); } $data = apply_filters('edd_export_get_data', $data); $data = apply_filters('edd_export_get_data_' . $this->export_type, $data); return $data; }
/** * Send purchase details to MailChimp's Ecommerce360 extension. * * @param integer $payment_id [description] * @return bool */ public function record_ecommerce360_purchase($payment_id = 0) { // Make sure an API key has been entered if (empty($this->key)) { return FALSE; } // Don't record details if we're in test mode if (edd_is_test_mode()) { return FALSE; } $payment = edd_get_payment_meta($payment_id); $user_info = edd_get_payment_meta_user_info($payment_id); $amount = edd_get_payment_amount($payment_id); $cart_details = edd_get_payment_meta_cart_details($payment_id); $tax = edd_get_payment_tax($payment_id); if (is_array($cart_details)) { $items = array(); // Increase purchase count and earnings foreach ($cart_details as $index => $download) { // Get the categories that this download belongs to, if any $post = edd_get_download($download['id']); $terms = get_the_terms($download['id'], 'download_category'); if ($terms && !is_wp_error($terms)) { $categories = array(); foreach ($terms as $term) { $categories[] = $term->name; } $category_id = $terms[0]->term_id; $category_name = join(" - ", $categories); } else { $category_id = 1; $category_name = 'Download'; } // "bundle" or "default" $download_type = edd_get_download_type($download['id']); $download['sku'] = edd_get_download_sku($download['id']); // if ( 'bundle' == $download_type ) { // $downloads = edd_get_bundled_products( $download_id ); // if ( $downloads ) { // foreach ( $downloads as $d_id ) { // # Do something // } // } // } $item = array('line_num' => $index + 1, 'product_id' => (int) $download['id'], 'product_name' => $download['name'], 'category_id' => $category_id, 'category_name' => $category_name, 'qty' => $download['quantity'], 'cost' => $download['subtotal']); if ($download['sku'] !== '-') { $item['sku'] = $download['sku']; // optional, 30 char limit } $items[] = $item; } $order = array('id' => (string) $payment_id, 'email' => $user_info['email'], 'total' => $amount, 'store_id' => self::_edd_ec360_get_store_id(), 'store_name' => home_url(), 'items' => $items, 'order_date' => get_the_date('Y-n-j', $payment_id)); // Set Ecommerce360 variables if they exist $campaign_id = get_post_meta($payment_id, '_edd_mc_campaign_id', true); $email_id = get_post_meta($payment_id, '_edd_mc_email_id', true); if (!empty($campaign_id)) { $order['campaign_id'] = $campaign_id; } if (!empty($email_id)) { $order['email_id'] = $email_id; } if ($tax != 0) { $order['tax'] = $tax; // double, optional } // Send to MailChimp $options = array('CURLOPT_FOLLOWLOCATION' => false); $mailchimp = new EDD_MailChimp_API($this->key, $options); try { $result = $mailchimp->call('ecomm/order-add', array('order' => $order)); edd_insert_payment_note($payment_id, __('Order details have been added to MailChimp successfully', 'eddmc')); } catch (Exception $e) { edd_insert_payment_note($payment_id, __('MailChimp Ecommerce360 Error: ', 'eddmc') . $e->getMessage()); return FALSE; } return TRUE; } else { return FALSE; } }
/** * Email template tag: value * The total value of the purchase * * @since 1.0.0 * @param int $payment_id * @return string value */ function edd_wallet_email_tag_value($payment_id) { if (get_post_type($payment_id) == 'edd_payment') { $value = edd_currency_filter(edd_format_amount(edd_get_payment_amount($payment_id)), edd_get_payment_currency_code($payment_id)); } else { $item = edd_wallet()->db->get_customer_wallet_item($payment_id); $value = edd_currency_filter(edd_format_amount($item->amount)); } return html_entity_decode($value, ENT_COMPAT, 'UTF-8'); }
/** * Get the Export Data * * @access public * @since 2.4 * @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 H:i:s', strtotime($this->start)), 'before' => date('Y-n-d H:i:s', strtotime($this->end)), 'inclusive' => true)); } //echo json_encode($args ); exit; $payments = edd_get_payments($args); if ($payments) { foreach ($payments as $payment) { $payment_meta = edd_get_payment_meta($payment->ID); $user_info = edd_get_payment_meta_user_info($payment->ID); $downloads = edd_get_payment_meta_cart_details($payment->ID); $total = edd_get_payment_amount($payment->ID); $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email']; $products = ''; $skus = ''; if ($downloads) { foreach ($downloads as $key => $download) { // Download ID $id = isset($payment_meta['cart_details']) ? $download['id'] : $download; // If the download has variable prices, override the default price $price_override = isset($payment_meta['cart_details']) ? $download['price'] : null; $price = edd_get_download_final_price($id, $user_info, $price_override); // Display the Downoad Name $products .= get_the_title($id) . ' - '; if (edd_use_skus()) { $sku = edd_get_download_sku($id); if (!empty($sku)) { $skus .= $sku; } } if (isset($downloads[$key]['item_number']) && isset($downloads[$key]['item_number']['options'])) { $price_options = $downloads[$key]['item_number']['options']; if (isset($price_options['price_id'])) { $products .= edd_get_price_option_name($id, $price_options['price_id'], $payment->ID) . ' - '; } } $products .= html_entity_decode(edd_currency_filter($price)); if ($key != count($downloads) - 1) { $products .= ' / '; if (edd_use_skus()) { $skus .= ' / '; } } } } if (is_numeric($user_id)) { $user = get_userdata($user_id); } else { $user = false; } $data[] = array('id' => $payment->ID, 'seq_id' => edd_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'] : '', 'products' => $products, 'skus' => $skus, 'amount' => html_entity_decode(edd_format_amount($total)), 'tax' => html_entity_decode(edd_format_amount(edd_get_payment_tax($payment->ID, $payment_meta))), 'discount' => isset($user_info['discount']) && $user_info['discount'] != 'none' ? $user_info['discount'] : __('none', 'edd'), 'gateway' => edd_get_gateway_admin_label(get_post_meta($payment->ID, '_edd_payment_gateway', true)), 'trans_id' => edd_get_payment_transaction_id($payment->ID), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'edd'), 'status' => edd_get_payment_status($payment, true)); } $data = apply_filters('edd_export_get_data', $data); $data = apply_filters('edd_export_get_data_' . $this->export_type, $data); return $data; } return false; }
/** * Get the fully formatted payment amount. The payment amount is retrieved using * edd_get_payment_amount() and is then sent through edd_currency_filter() and * edd_format_amount() to format the amount correctly. * * @since 1.4 * @param int $payment_id Payment ID * @return string $amount Fully formatted payment amount */ function edd_payment_amount($payment_id = 0) { $amount = edd_get_payment_amount($payment_id); return edd_currency_filter(edd_format_amount($amount), edd_get_payment_currency_code($payment_id)); }
function edd_userpro_embed_profile_fields($hook_args) { if (!current_user_can('edit_user', $hook_args['user_id'])) { return; } echo '<div class="userpro-section userpro-column userpro-collapsible-1 userpro-collapsed-1">' . __('Purchase History', 'edd-userpro-embed') . '</div>'; echo '<div class="userpro-field userpro-field-edd-purchase-history userpro-field-view" data-key="edd-purchase-history">'; $purchases = edd_get_users_purchases($hook_args['user_id'], 99999, true, 'any'); if ($purchases) { do_action('edd_before_purchase_history'); ?> <table id="edd_user_history"> <thead> <tr class="edd_purchase_row"> <?php do_action('edd_purchase_history_header_before'); ?> <th class="edd_purchase_id"><?php _e('ID', 'easy-digital-downloads'); ?> </th> <th class="edd_purchase_date"><?php _e('Date', 'easy-digital-downloads'); ?> </th> <th class="edd_purchase_amount"><?php _e('Amount', 'easy-digital-downloads'); ?> </th> <th class="edd_purchase_details"><?php _e('Details', 'easy-digital-downloads'); ?> </th> <?php do_action('edd_purchase_history_header_after'); ?> </tr> </thead> <?php foreach ($purchases as $post) { setup_postdata($post); ?> <?php $purchase_data = edd_get_payment_meta($post->ID); ?> <tr class="edd_purchase_row"> <?php do_action('edd_purchase_history_row_start', $post->ID, $purchase_data); ?> <td class="edd_purchase_id">#<?php echo edd_get_payment_number($post->ID); ?> </td> <td class="edd_purchase_date"><?php echo date_i18n(get_option('date_format'), strtotime(get_post_field('post_date', $post->ID))); ?> </td> <td class="edd_purchase_amount"> <span class="edd_purchase_amount"><?php echo edd_currency_filter(edd_format_amount(edd_get_payment_amount($post->ID))); ?> </span> </td> <td class="edd_purchase_details"> <?php if ($post->post_status != 'publish') { ?> <span class="edd_purchase_status <?php echo $post->post_status; ?> "><?php echo edd_get_payment_status($post, true); ?> </span> <a href="<?php echo esc_url(add_query_arg('payment_key', edd_get_payment_key($post->ID), edd_get_success_page_uri())); ?> ">»</a> <?php } else { ?> <a href="<?php echo esc_url(add_query_arg('payment_key', edd_get_payment_key($post->ID), edd_get_success_page_uri())); ?> "><?php _e('View Details', 'edd-userpro-embed'); ?> </a> <?php } ?> </td> <?php do_action('edd_purchase_history_row_end', $post->ID, $purchase_data); ?> </tr> <?php } ?> </table> <?php do_action('edd_after_purchase_history'); ?> <?php wp_reset_postdata(); ?> <?php } else { ?> <p class="edd-no-purchases"><?php _e('You have not made any purchases', 'edd-userpro-embed'); ?> </p> <?php } echo '</div>'; }
/** * Sale Notification Template Body * * @since 1.7 * @author Daniel J Griffiths * @param int $payment_id Payment ID * @param array $payment_data Payment Data * @return string $email_body Body of the email */ function edd_get_sale_notification_body_content($payment_id = 0, $payment_data = array()) { global $edd_options; $user_info = maybe_unserialize($payment_data['user_info']); $email = edd_get_payment_user_email($payment_id); if (isset($user_info['id']) && $user_info['id'] > 0) { $user_data = get_userdata($user_info['id']); $name = $user_data->display_name; } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) { $name = $user_info['first_name'] . ' ' . $user_info['last_name']; } else { $name = $email; } $download_list = ''; $downloads = maybe_unserialize($payment_data['downloads']); if (is_array($downloads)) { foreach ($downloads as $download) { $id = isset($payment_data['cart_details']) ? $download['id'] : $download; $title = get_the_title($id); if (isset($download['options'])) { if (isset($download['options']['price_id'])) { $title .= ' - ' . edd_get_price_option_name($id, $download['options']['price_id'], $payment_id); } } $download_list .= html_entity_decode($title, ENT_COMPAT, 'UTF-8') . "\n"; } } $gateway = edd_get_gateway_admin_label(get_post_meta($payment_id, '_edd_payment_gateway', true)); $default_email_body = __('Hello', 'edd') . "\n\n" . sprintf(__('A %s purchase has been made', 'edd'), edd_get_label_plural()) . ".\n\n"; $default_email_body .= sprintf(__('%s sold:', 'edd'), edd_get_label_plural()) . "\n\n"; $default_email_body .= $download_list . "\n\n"; $default_email_body .= __('Purchased by: ', 'edd') . " " . html_entity_decode($name, ENT_COMPAT, 'UTF-8') . "\n"; $default_email_body .= __('Amount: ', 'edd') . " " . html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_payment_amount($payment_id))), ENT_COMPAT, 'UTF-8') . "\n"; $default_email_body .= __('Payment Method: ', 'edd') . " " . $gateway . "\n\n"; $default_email_body .= __('Thank you', 'edd'); $email = isset($edd_options['sale_notification']) ? stripslashes($edd_options['sale_notification']) : $default_email_body; //$email_body = edd_email_template_tags( $email, $payment_data, $payment_id, true ); $email_body = edd_do_email_tags($email, $payment_id); return apply_filters('edd_sale_notification', wpautop($email_body), $payment_id, $payment_data); }
/** * Retrieve all the data for all the payments * * @access public * @since 1.4 * @return array $payment_data Array of all the data for the payments */ public function payments_data() { $payments_data = array(); if (isset($_GET['paged'])) { $page = $_GET['paged']; } else { $page = 1; } $per_page = $this->per_page; $mode = edd_is_test_mode() ? 'test' : 'live'; $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'ID'; $order = isset($_GET['order']) ? $_GET['order'] : 'DESC'; $order_inverse = $order == 'DESC' ? 'ASC' : 'DESC'; $order_class = strtolower($order_inverse); $user = isset($_GET['user']) ? $_GET['user'] : null; $status = isset($_GET['status']) ? $_GET['status'] : 'any'; $meta_key = isset($_GET['meta_key']) ? $_GET['meta_key'] : null; $year = isset($_GET['year']) ? $_GET['year'] : null; $month = isset($_GET['m']) ? $_GET['m'] : null; $day = isset($_GET['day']) ? $_GET['day'] : null; $search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : null; $payments = edd_get_payments(array('number' => $per_page, 'page' => isset($_GET['paged']) ? $_GET['paged'] : null, 'mode' => $mode, 'orderby' => $orderby, 'order' => $order, 'user' => $user, 'status' => $status, 'meta_key' => $meta_key, 'year' => $year, 'month' => $month, 'day' => $day, 's' => $search)); if ($payments) { foreach ($payments as $payment) { $user_info = edd_get_payment_meta_user_info($payment->ID); $cart_details = edd_get_payment_meta_cart_details($payment->ID); $user_id = isset($user_info['ID']) && $user_info['ID'] != -1 ? $user_info['ID'] : $user_info['email']; $payments_data[] = array('ID' => $payment->ID, 'email' => edd_get_payment_user_email($payment->ID), 'products' => $cart_details, 'amount' => edd_get_payment_amount($payment->ID), 'date' => $payment->post_date, 'user' => $user_id, 'status' => $payment->post_status); } } return $payments_data; }
/** * Process the payment details edit * * @access private * @since 1.9 * @return void */ function edd_update_payment_details($data) { if (!current_user_can('edit_shop_payments', $data['edd_payment_id'])) { wp_die(__('You do not have permission to edit this payment record', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403)); } check_admin_referer('edd_update_payment_details_nonce'); // Retrieve the payment ID $payment_id = absint($data['edd_payment_id']); // Retrieve existing payment meta $meta = edd_get_payment_meta($payment_id); $user_info = edd_get_payment_meta_user_info($payment_id); $status = $data['edd-payment-status']; $unlimited = isset($data['edd-unlimited-downloads']) ? '1' : ''; $date = sanitize_text_field($data['edd-payment-date']); $hour = sanitize_text_field($data['edd-payment-time-hour']); // Restrict to our high and low if ($hour > 23) { $hour = 23; } elseif ($hour < 0) { $hour = 00; } $minute = sanitize_text_field($data['edd-payment-time-min']); // Restrict to our high and low if ($minute > 59) { $minute = 59; } elseif ($minute < 0) { $minute = 00; } $address = array_map('trim', $data['edd-payment-address'][0]); $curr_total = edd_sanitize_amount(edd_get_payment_amount($payment_id)); $new_total = edd_sanitize_amount($_POST['edd-payment-total']); $tax = isset($_POST['edd-payment-tax']) ? edd_sanitize_amount($_POST['edd-payment-tax']) : 0; $date = date('Y-m-d', strtotime($date)) . ' ' . $hour . ':' . $minute . ':00'; $curr_customer_id = sanitize_text_field($data['edd-current-customer']); $new_customer_id = sanitize_text_field($data['customer-id']); // Setup purchased Downloads and price options $updated_downloads = isset($_POST['edd-payment-details-downloads']) ? $_POST['edd-payment-details-downloads'] : false; if ($updated_downloads && !empty($_POST['edd-payment-downloads-changed'])) { $downloads = array(); $cart_details = array(); $i = 0; foreach ($updated_downloads as $download) { if (empty($download['amount'])) { $download['amount'] = '0.00'; } $item = array(); $item['id'] = absint($download['id']); $item['quantity'] = absint($download['quantity']) > 0 ? absint($download['quantity']) : 1; $price_id = (int) $download['price_id']; $has_log = absint($download['has_log']); if ($price_id !== false && edd_has_variable_prices($item['id'])) { $item['options'] = array('price_id' => $price_id); } $downloads[] = $item; $cart_item = array(); $cart_item['item_number'] = $item; $item_price = round($download['amount'] / $item['quantity'], edd_currency_decimal_filter()); $cart_details[$i] = array('name' => get_the_title($download['id']), 'id' => $download['id'], 'item_number' => $item, 'price' => $download['amount'], 'item_price' => $item_price, 'subtotal' => $download['amount'], 'quantity' => $download['quantity'], 'discount' => 0, 'tax' => 0); // If this item doesn't have a log yet, add one for each quantity count if (empty($has_log)) { $log_date = date('Y-m-d G:i:s', current_time('timestamp', true)); $price_id = $price_id !== false ? $price_id : 0; $y = 0; while ($y < $download['quantity']) { edd_record_sale_in_log($download['id'], $payment_id, $price_id, $log_date); $y++; } edd_increase_purchase_count($download['id'], $download['quantity']); edd_increase_earnings($download['id'], $download['amount']); } $i++; } $meta['downloads'] = $downloads; $meta['cart_details'] = $cart_details; $deleted_downloads = json_decode(stripcslashes($data['edd-payment-removed']), true); foreach ($deleted_downloads as $deleted_download) { $deleted_download = $deleted_download[0]; if (empty($deleted_download['id'])) { continue; } $price_id = empty($deleted_download['price_id']) ? 0 : (int) $deleted_download['price_id']; $log_args = array('post_type' => 'edd_log', 'post_parent' => $deleted_download['id'], 'numberposts' => $deleted_download['quantity'], 'meta_query' => array(array('key' => '_edd_log_payment_id', 'value' => $payment_id, 'compare' => '='), array('key' => '_edd_log_price_id', 'value' => $price_id, 'compare' => '='))); $found_logs = get_posts($log_args); foreach ($found_logs as $log) { wp_delete_post($log->ID, true); } edd_decrease_purchase_count($deleted_download['id'], $deleted_download['quantity']); edd_decrease_earnings($deleted_download['id'], $deleted_download['amount']); do_action('edd_remove_download_from_payment', $payment_id, $deleted_download['id']); } } do_action('edd_update_edited_purchase', $payment_id); // Update main payment record $updated = wp_update_post(array('ID' => $payment_id, 'post_date' => $date)); if (0 === $updated) { wp_die(__('Error Updating Payment', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 400)); } $customer_changed = false; if (isset($data['edd-new-customer']) && $data['edd-new-customer'] == '1') { $email = isset($data['edd-new-customer-email']) ? sanitize_text_field($data['edd-new-customer-email']) : ''; $names = isset($data['edd-new-customer-name']) ? sanitize_text_field($data['edd-new-customer-name']) : ''; if (empty($email) || empty($names)) { wp_die(__('New Customers require a name and email address', 'easy-digital-downloads')); } $customer = new EDD_Customer($email); if (empty($customer->id)) { $customer_data = array('name' => $names, 'email' => $email); $user_id = email_exists($email); if (false !== $user_id) { $customer_data['user_id'] = $user_id; } if (!$customer->create($customer_data)) { // Failed to crete the new customer, assume the previous customer $customer_changed = false; $customer = new EDD_Customer($curr_customer_id); edd_set_error('edd-payment-new-customer-fail', __('Error creating new customer', 'easy-digital-downloads')); } } $new_customer_id = $customer->id; $previous_customer = new EDD_Customer($curr_customer_id); $customer_changed = true; } elseif ($curr_customer_id !== $new_customer_id) { $customer = new EDD_Customer($new_customer_id); $email = $customer->email; $names = $customer->name; $previous_customer = new EDD_Customer($curr_customer_id); $customer_changed = true; } else { $customer = new EDD_Customer($curr_customer_id); $email = $customer->email; $names = $customer->name; } // Setup first and last name from input values $names = explode(' ', $names); $first_name = !empty($names[0]) ? $names[0] : ''; $last_name = ''; if (!empty($names[1])) { unset($names[0]); $last_name = implode(' ', $names); } if ($customer_changed) { // Remove the stats and payment from the previous customer and attach it to the new customer $previous_customer->remove_payment($payment_id, false); $customer->attach_payment($payment_id, false); // If purchase was completed and not ever refunded, adjust stats of customers if ('revoked' == $status || 'publish' == $status) { $previous_customer->decrease_purchase_count(); $previous_customer->decrease_value($new_total); $customer->increase_purchase_count(); $customer->increase_value($new_total); } update_post_meta($payment_id, '_edd_payment_customer_id', $customer->id); } // Set new meta values $user_info['id'] = $customer->user_id; $user_info['email'] = $customer->email; $user_info['first_name'] = $first_name; $user_info['last_name'] = $last_name; $user_info['address'] = $address; $meta['user_info'] = $user_info; $meta['tax'] = $tax; // Check for payment notes if (!empty($data['edd-payment-note'])) { $note = wp_kses($data['edd-payment-note'], array()); edd_insert_payment_note($payment_id, $note); } // Set new status edd_update_payment_status($payment_id, $status); edd_update_payment_meta($payment_id, '_edd_payment_user_id', $customer->user_id); edd_update_payment_meta($payment_id, '_edd_payment_user_email', $customer->email); edd_update_payment_meta($payment_id, '_edd_payment_meta', $meta); edd_update_payment_meta($payment_id, '_edd_payment_total', $new_total); // Adjust total store earnings if the payment total has been changed if ($new_total !== $curr_total && ('publish' == $status || 'revoked' == $status)) { if ($new_total > $curr_total) { // Increase if our new total is higher $difference = $new_total - $curr_total; edd_increase_total_earnings($difference); } elseif ($curr_total > $new_total) { // Decrease if our new total is lower $difference = $curr_total - $new_total; edd_decrease_total_earnings($difference); } } edd_update_payment_meta($payment_id, '_edd_payment_downloads', $new_total); edd_update_payment_meta($payment_id, '_edd_payment_unlimited_downloads', $unlimited); do_action('edd_updated_edited_purchase', $payment_id); wp_safe_redirect(admin_url('edit.php?post_type=download&page=edd-payment-history&view=view-order-details&edd-message=payment-updated&id=' . $payment_id)); exit; }
/** * Retrieves Recent Sales * * @access public * @since 1.5 * @return array */ public function get_recent_sales() { global $wp_query; $sales = array(); if( ! user_can( $this->user_id, 'view_shop_reports' ) && ! $this->override ) { return $sales; } if( isset( $wp_query->query_vars['id'] ) ) { $query = array(); $query[] = edd_get_payment_by( 'id', $wp_query->query_vars['id'] ); } elseif( isset( $wp_query->query_vars['purchasekey'] ) ) { $query = array(); $query[] = edd_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); } elseif( isset( $wp_query->query_vars['email'] ) ) { $query = edd_get_payments( array( 'meta_key' => '_edd_payment_user_email', 'meta_value' => $wp_query->query_vars['email'], 'number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish' ) ); } else { $query = edd_get_payments( array( 'number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish' ) ); } if ( $query ) { $i = 0; foreach ( $query as $payment ) { $payment_meta = edd_get_payment_meta( $payment->ID ); $user_info = edd_get_payment_meta_user_info( $payment->ID ); $cart_items = edd_get_payment_meta_cart_details( $payment->ID ); $sales['sales'][ $i ]['ID'] = edd_get_payment_number( $payment->ID ); $sales['sales'][ $i ]['transaction_id'] = edd_get_payment_transaction_id( $payment->ID ); $sales['sales'][ $i ]['key'] = edd_get_payment_key( $payment->ID ); $sales['sales'][ $i ]['discount'] = isset( $user_info['discount'] ) && $user_info['discount'] != 'none' ? explode( ',', $user_info['discount'] ) : array(); $sales['sales'][ $i ]['subtotal'] = edd_get_payment_subtotal( $payment->ID ); $sales['sales'][ $i ]['tax'] = edd_get_payment_tax( $payment->ID ); $sales['sales'][ $i ]['fees'] = edd_get_payment_fees( $payment->ID ); $sales['sales'][ $i ]['total'] = edd_get_payment_amount( $payment->ID ); $sales['sales'][ $i ]['gateway'] = edd_get_payment_gateway( $payment->ID ); $sales['sales'][ $i ]['email'] = edd_get_payment_user_email( $payment->ID ); $sales['sales'][ $i ]['date'] = $payment->post_date; $sales['sales'][ $i ]['products'] = array(); $c = 0; foreach ( $cart_items as $key => $item ) { $item_id = isset( $item['id'] ) ? $item['id'] : $item; $price = isset( $item['price'] ) ? $item['price'] : false; $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; $quantity = isset( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; if( ! $price ) { // This function is only used on payments with near 1.0 cart data structure $price = edd_get_download_final_price( $item_id, $user_info, null ); } $price_name = ''; if ( isset( $item['item_number'] ) && isset( $item['item_number']['options'] ) ) { $price_options = $item['item_number']['options']; if ( isset( $price_options['price_id'] ) ) { $price_name = edd_get_price_option_name( $item['id'], $price_options['price_id'], $payment->ID ); } } $sales['sales'][ $i ]['products'][ $c ]['quantity'] = $quantity; $sales['sales'][ $i ]['products'][ $c ]['name'] = get_the_title( $item['id'] ); $sales['sales'][ $i ]['products'][ $c ]['price'] = $price; $sales['sales'][ $i ]['products'][ $c ]['price_name'] = $price_name; $c++; } $i++; } } return $sales; }
/** * Remove a payment from this customer, then triggers reducing stats * * @since 2.3 * @param integer $payment_id The Payment ID to remove * @param bool $update_stats For backwards compatibility, if we should increase the stats or not * @return boolean If the removal was successful */ public function remove_payment($payment_id = 0, $update_stats = true) { if (empty($payment_id)) { return false; } $new_payment_ids = ''; if (!empty($this->payment_ids)) { $payment_ids = array_map('absint', explode(',', $this->payment_ids)); $pos = array_search($payment_id, $payment_ids); if (false === $pos) { return false; } unset($payment_ids[$pos]); $payment_ids = array_filter($payment_ids); $new_payment_ids = implode(',', array_unique(array_values($payment_ids))); } do_action('edd_customer_pre_remove_payment', $payment_id, $this->id); $payment_removed = $this->update(array('payment_ids' => $new_payment_ids)); if ($payment_removed) { $this->payment_ids = $new_payment_ids; if ($update_stats) { // We removed this payment successfully, decrement the stats $payment_amount = edd_get_payment_amount($payment_id); if (!empty($payment_amount)) { $this->decrease_value($payment_amount); } $this->decrease_purchase_count(); } } do_action('edd_customer_post_remove_payment', $payment_removed, $payment_id, $this->id); return $payment_removed; }
/** * Retrieves Recent Sales * * @access public * @since 1.5 * @return array */ public function get_recent_sales() { $sales = array(); $query = edd_get_payments(array('number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish')); if ($query) { $i = 0; foreach ($query as $payment) { $payment_meta = edd_get_payment_meta($payment->ID); $user_info = edd_get_payment_meta_user_info($payment->ID); $cart_items = edd_get_payment_meta_cart_details($payment->ID); $sales['sales'][$i]['ID'] = $payment->ID; $sales['sales'][$i]['key'] = edd_get_payment_key($payment->ID); $sales['sales'][$i]['subtotal'] = edd_get_payment_subtotal($payment->ID); $sales['sales'][$i]['tax'] = edd_get_payment_tax($payment->ID); $sales['sales'][$i]['fees'] = edd_get_payment_fees($payment->ID); $sales['sales'][$i]['total'] = edd_get_payment_amount($payment->ID); $sales['sales'][$i]['gateway'] = edd_get_payment_gateway($payment->ID); $sales['sales'][$i]['email'] = edd_get_payment_user_email($payment->ID); $sales['sales'][$i]['date'] = $payment->post_date; $sales['sales'][$i]['products'] = array(); $c = 0; foreach ($cart_items as $key => $item) { $price_override = isset($payment_meta['cart_details']) ? $item['price'] : null; $price = edd_get_download_final_price($item['id'], $user_info, $price_override); if (isset($cart_items[$key]['item_number'])) { $price_name = ''; $price_options = $cart_items[$key]['item_number']['options']; if (isset($price_options['price_id'])) { $price_name = edd_get_price_option_name($item['id'], $price_options['price_id'], $payment->ID); } } $sales['sales'][$i]['products'][$c]['name'] = get_the_title($item['id']); $sales['sales'][$i]['products'][$c]['price'] = $price; $sales['sales'][$i]['products'][$c]['price_name'] = $price_name; $c++; } $i++; } } return $sales; }
/** * Get the backer's pledge amount. * * @param WP_Post $backer * @param bool $formatted * @return string */ function wpo_crowdfunding_get_backer_pledge($backer, $formatted = true) { if ($formatted) { return edd_currency_filter(edd_format_amount(edd_get_payment_amount($backer->ID))); } return edd_get_payment_amount($backer->ID); }
/** * Process refunds * * @access public * @since 1.0.0 * @param int $payment_id The ID of a payment * @param string $new_status The new status of the payment * @param string $old_status The old status of the payment * @return void */ public function process_refund($payment_id, $new_status, $old_status) { if ($old_status != 'publish' && $old_status != 'revoked') { return; } if ($new_status != 'refunded') { return; } if (edd_get_payment_gateway($payment_id) !== 'wallet') { return; } $user_id = edd_get_payment_user_id($payment_id); $refund_amount = edd_get_payment_amount($payment_id); // Deposit the funds edd_wallet()->wallet->deposit($user_id, $refund_amount, 'refund'); // Insert payment note edd_insert_payment_note($payment_id, __('Refund completed to Wallet.', 'edd-wallet')); }
/** * Email template tag: price * The total price of the purchase * * @param int $payment_id * * @return string price */ function edd_email_tag_price($payment_id) { $price = edd_currency_filter(edd_format_amount(edd_get_payment_amount($payment_id)), edd_get_payment_currency_code($payment_id)); return html_entity_decode($price, ENT_COMPAT, 'UTF-8'); }
/** * Process PayPal IPN Refunds * * @since 1.3.4 * @param array $data IPN Data * @return void */ function edd_process_paypal_refund($data, $payment_id = 0) { // Collect payment details if (empty($payment_id)) { return; } if (get_post_status($payment_id) == 'refunded') { return; // Only refund payments once } $payment_amount = edd_get_payment_amount($payment_id); $refund_amount = $data['payment_gross'] * -1; if (number_format((double) $refund_amount, 2) < number_format((double) $payment_amount, 2)) { edd_insert_payment_note($payment_id, sprintf(__('Partial PayPal refund processed: %s', 'edd'), $data['parent_txn_id'])); return; // This is a partial refund } edd_insert_payment_note($payment_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'edd'), $data['parent_txn_id'], $data['reason_code'])); edd_insert_payment_note($payment_id, sprintf(__('PayPal Refund Transaction ID: %s', 'edd'), $data['txn_id'])); edd_update_payment_status($payment_id, 'refunded'); }
/** * Retrieves subtotal for payment (this is the amount before taxes) and then * returns a non formatted amount. * * @since 1.3.3 * @param int $payment_id Payment ID * @return float $subtotal Subtotal for payment (non formatted) */ function edd_get_payment_subtotal($payment_id = 0) { $subtotal = 0; $cart_details = edd_get_payment_meta_cart_details($payment_id); if (is_array($cart_details)) { foreach ($cart_details as $item) { if (isset($item['subtotal'])) { $subtotal += $item['subtotal']; } } } else { $subtotal = edd_get_payment_amount($payment_id); $tax = edd_use_taxes() ? edd_get_payment_tax($payment_id) : 0; $subtotal -= $tax; } return apply_filters('edd_get_payment_subtotal', $subtotal, $payment_id); }
/** * Reduces earnings and sales stats when a purchase is refunded * * @since 1.8.2 * @param $data Arguments passed * @return void */ function edd_undo_purchase_on_refund($payment_id, $new_status, $old_status) { if ('publish' != $old_status && 'revoked' != $old_status) { return; } if ('refunded' != $new_status) { return; } $downloads = edd_get_payment_meta_cart_details($payment_id); if ($downloads) { foreach ($downloads as $download) { edd_undo_purchase($download['id'], $payment_id); } } // Decrease store earnings $amount = edd_get_payment_amount($payment_id); edd_decrease_total_earnings($amount); // Decrement the stats for the customer $customer_id = edd_get_payment_customer_id($payment_id); if ($customer_id) { $customer = new EDD_Customer($customer_id); $customer->decrease_value($amount); $customer->decrease_purchase_count(); } // Clear the This Month earnings (this_monththis_month is NOT a typo) delete_transient(md5('edd_earnings_this_monththis_month')); }
/** * Refund a charge in Amazon * * @access public * @since 2.4 * @param $payment_id int The ID number of the payment being refunded * @return string */ private function refund($payment_id = 0) { $refund = $this->client->refund(array('merchant_id' => edd_get_option('amazon_seller_id', ''), 'amazon_capture_id' => edd_get_payment_meta($payment_id, '_edd_amazon_capture_id', true), 'refund_reference_id' => md5(edd_get_payment_key($payment_id) . '-refund'), 'refund_amount' => edd_get_payment_amount($payment_id), 'currency_code' => edd_get_payment_currency_code($payment_id))); if (200 == $refund->response['Status']) { $refund = new ResponseParser($refund->response); $refund = $refund->toArray(); $reference_id = $refund['RefundResult']['RefundDetails']['RefundReferenceId']; $status = $refund['RefundResult']['RefundDetails']['RefundStatus']['State']; switch ($status) { case 'Declined': $code = $refund['RefundResult']['RefundDetails']['RefundStatus']['ReasonCode']; $note = __('Refund declined in Amazon. Refund ID: %s', 'edd'); break; case 'Completed': $refund_id = $refund['RefundResult']['RefundDetails']['AmazonRefundId']; $note = sprintf(__('Refund completed in Amazon. Refund ID: %s', 'edd'), $refund_id); break; case 'Pending': $note = sprintf(__('Refund initiated in Amazon. Reference ID: %s', 'edd'), $reference_id); break; } edd_insert_payment_note($payment_id, $note); } else { edd_insert_payment_note($payment_id, __('Refund request failed in Amazon.', 'edd')); } }
</div> <?php } ?> <div class="edd-order-payment edd-admin-box-inside"> <p> <span class="label"><?php _e('Total Price', 'edd'); ?> :</span> <?php echo edd_currency_symbol($payment_meta['currency']); ?> <input name="edd-payment-total" type="text" class="med-text" value="<?php echo esc_attr(edd_format_amount(edd_get_payment_amount($payment_id))); ?> "/> </p> </div> <div class="edd-order-payment-recalc-totals edd-admin-box-inside" style="display:none"> <p> <span class="label"><?php _e('Recalculate Totals', 'edd'); ?> :</span> <a href="" id="edd-order-recalc-total" class="button button-secondary right"><?php _e('Recalculate', 'edd'); ?> </a>
<tr class="edd_purchase_row"> <?php do_action('edd_purchase_history_row_start', $post->ID, $purchase_data); ?> <td class="edd_purchase_id">#<?php echo edd_get_payment_number($post->ID); ?> </td> <td class="edd_purchase_date"><?php echo date_i18n(get_option('date_format'), strtotime(get_post_field('post_date', $post->ID))); ?> </td> <td class="edd_purchase_amount"> <span class="edd_purchase_amount"><?php echo edd_currency_filter(edd_format_amount(edd_get_payment_amount($post->ID))); ?> </span> </td> <td class="edd_purchase_details"> <?php if ($post->post_status != 'publish') { ?> <span class="edd_purchase_status <?php echo $post->post_status; ?> "><?php echo edd_get_payment_status($post, true); ?> </span> <a href="<?php
/** * Sales Summary Dashboard Widget * * Builds and renders the Sales Summary dashboard widget. This widget displays * the current month's sales and earnings, total sales and earnings best selling * downloads as well as recent purchases made on your EDD Store. * * @author Sunny Ratilal * @since 1.2.2 * @return void */ function edd_dashboard_sales_widget() { $top_selling_args = array('post_type' => 'download', 'posts_per_page' => 1, 'post_status' => 'publish', 'meta_key' => '_edd_download_sales', 'meta_compare' => '>', 'meta_value' => 0, 'orderby' => 'meta_value_num', 'update_post_term_cache' => false, 'order' => 'DESC'); $top_selling = get_posts($top_selling_args); ?> <div class="edd_dashboard_widget"> <div class="table table_left table_current_month"> <p class="sub"><?php _e('Current Month', 'edd'); ?> </p> <table> <tbody> <tr class="first"> <td class="first b"><?php echo edd_currency_filter(edd_format_amount(edd_get_earnings_by_date(null, date('n'), date('Y')))); ?> </td> <td class="t monthly_earnings"><?php _e('Earnings', 'edd'); ?> </td> </tr> <tr> <?php $monthly_sales = edd_get_sales_by_date(null, date('n'), date('Y')); ?> <td class="first b"><?php echo $monthly_sales; ?> </td> <td class="t monthly_sales"><?php echo _n('Sale', 'Sales', $monthly_sales, 'edd'); ?> </td> </tr> </tbody> </table> <p class="label_heading"><?php _e('Last Month', 'edd'); ?> </p> <?php $previous_month = date('n') == 1 ? 12 : date('n') - 1; $previous_year = $previous_month == 12 ? date('Y') - 1 : date('Y'); ?> <div> <?php echo __('Earnings', 'edd') . ': <span class="edd_price_label">' . edd_currency_filter(edd_format_amount(edd_get_earnings_by_date(null, $previous_month, $previous_year))) . '</span>'; ?> </div> <div> <?php $last_month_sales = edd_get_sales_by_date(null, $previous_month, $previous_year); ?> <?php echo _n('Sale', 'Sales', $last_month_sales, 'edd') . ': ' . '<span class="edd_price_label">' . $last_month_sales . '</span>'; ?> </div> </div> <div class="table table_right table_totals"> <p class="sub"><?php _e('Totals', 'edd'); ?> </p> <table> <tbody> <tr class="first"> <td class="b b-earnings"><?php echo edd_currency_filter(edd_format_amount(edd_get_total_earnings())); ?> </td> <td class="last t earnings"><?php _e('Total Earnings', 'edd'); ?> </td> </tr> <tr> <td class="b b-sales"><?php echo edd_get_total_sales(); ?> </td> <td class="last t sales"><?php _e('Total Sales', 'edd'); ?> </td> </tr> </tbody> </table> <?php if ($top_selling) { foreach ($top_selling as $list) { ?> <p class="lifetime_best_selling label_heading"><?php _e('Lifetime Best Selling', 'edd'); ?> </p> <p><span class="lifetime_best_selling_label"><?php echo edd_get_download_sales_stats($list->ID); ?> </span> <a href="<?php echo get_permalink($list->ID); ?> "><?php echo get_the_title($list->ID); ?> </a></p> <?php } } ?> </div> <div style="clear: both"></div> <?php $payments = edd_get_payments(array('number' => 5, 'mode' => 'live', 'orderby' => 'post_date', 'order' => 'DESC', 'user' => null, 'status' => 'publish', 'meta_key' => null, 'fields' => 'ids')); if ($payments) { ?> <p class="edd_dashboard_widget_subheading"><?php _e('Recent Purchases', 'edd'); ?> </p> <div class="table recent_purchases"> <table> <tbody> <?php foreach ($payments as $payment) { $payment_meta = edd_get_payment_meta($payment); ?> <tr> <td> <?php echo get_the_title($payment); ?> - (<?php echo $payment_meta['email']; ?> ) - <span class="edd_price_label"><?php echo edd_currency_filter(edd_format_amount(edd_get_payment_amount($payment))); ?> </span> - <a href="<?php echo add_query_arg('id', $payment, admin_url('edit.php?post_type=download&page=edd-payment-history&edd-action=view-order-details')); ?> " title="<?php printf(__('Purchase Details for Payment #%s', 'edd'), $payment); ?> "><?php _e('View Order Details', 'edd'); ?> </a> </td> </tr> <?php } // End foreach ?> </tbody> </table> </div> <?php } // End if ?> </div> <?php }
/** * Retrieve upgrade count and earnings for specific date * * @since 3.3 * @return array */ function edd_sl_get_upgrades_by_date($day = null, $month = null, $year = null, $hour = null) { $args = apply_filters('edd_get_upgrades_by_date', array('nopaging' => true, 'post_type' => 'edd_payment', 'post_status' => array('revoked', 'publish'), 'meta_key' => '_edd_sl_upgraded_payment_id', 'year' => $year, 'monthnum' => $month, 'fields' => 'ids'), $day, $month, $year); if (!empty($day)) { $args['day'] = $day; } if (!empty($hour)) { $args['hour'] = $hour; } $upgrades = get_posts($args); $return = array(); $return['earnings'] = 0; $return['count'] = count($upgrades); if ($upgrades) { foreach ($upgrades as $upgrade) { $return['earnings'] += edd_get_payment_amount($upgrade); } } return $return; }