/** * 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.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; }
/** * Gets the sales tax for the current year * * @since 1.3.3 * @param $year int The year to retrieve taxes for, i.e. 2012 * @uses edd_get_payment_tax() * @return float $tax Sales tax */ function edd_get_sales_tax_for_year($year = null) { // Start at zero $tax = 0; if (!empty($year)) { $args = array('post_type' => 'edd_payment', 'post_status' => array('publish', 'revoked'), 'posts_per_page' => -1, 'year' => $year, 'fields' => 'ids'); $payments = get_posts($args); if ($payments) { foreach ($payments as $payment) { $tax += edd_get_payment_tax($payment); } } } return apply_filters('edd_get_sales_tax_for_year', $tax, $year); }
/** * Retrieves taxed amount for payment and then returns a full formatted amount * This function essentially calls edd_get_payment_tax() * * @since 1.3.3 * @see edd_get_payment_tax() * @param int $payment_id Payment ID * @param bool $payment_meta Payment Meta provided? (default: false) * @return string $subtotal Fully formatted payment subtotal */ function edd_payment_tax($payment_id = 0, $payment_meta = false) { $tax = edd_get_payment_tax($payment_id, $payment_meta); return edd_currency_filter(edd_format_amount($tax), edd_get_payment_currency_code($payment_id)); }
/** * 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; }
/** * 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; }
/** * Email template tag: tax * The taxed amount of the purchase * * @param int $payment_id * * @return string tax */ function edd_email_tag_tax($payment_id) { $tax = edd_currency_filter(edd_format_amount(edd_get_payment_tax($payment_id)), edd_get_payment_currency_code($payment_id)); return html_entity_decode($tax, 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, 'order' => 'ASC', 'orderby' => 'date'); 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 = edd_get_payments($args); if ($payments) { foreach ($payments as $payment) { $payment = new EDD_Payment($payment->ID); $payment_meta = $payment->payment_meta; $user_info = $payment->user_info; $downloads = $payment->cart_details; $total = $payment->total; $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email']; $products = ''; $products_raw = ''; $skus = ''; if ($downloads) { foreach ($downloads as $key => $download) { // Download ID $id = isset($payment_meta['cart_details']) ? $download['id'] : $download; $qty = isset($download['quantity']) ? $download['quantity'] : 1; if (isset($download['price'])) { $price = $download['price']; } else { // 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); } $download_tax = isset($download['tax']) ? $download['tax'] : 0; /* Set up verbose product column */ $products .= html_entity_decode(get_the_title($id)); if ($qty > 1) { $products .= html_entity_decode(' (' . $qty . ')'); } $products .= ' - '; 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']) && !is_null($price_options['price_id'])) { $products .= html_entity_decode(edd_get_price_option_name($id, $price_options['price_id'], $payment->ID)) . ' - '; } } $products .= html_entity_decode(edd_currency_filter(edd_format_amount($price))); if ($key != count($downloads) - 1) { $products .= ' / '; if (edd_use_skus()) { $skus .= ' / '; } } /* Set up raw products column - Nothing but product names */ $products_raw .= html_entity_decode(get_the_title($id)) . '|' . $price . '{' . $download_tax . '}'; if ($key != count($downloads) - 1) { $products_raw .= ' / '; } } } if (is_numeric($user_id)) { $user = get_userdata($user_id); } else { $user = false; } $data[] = array('id' => $payment->ID, 'seq_id' => $payment->number, 'email' => $payment_meta['email'], 'customer_id' => $payment->customer_id, '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, 'products_raw' => $products_raw, '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', 'easy-digital-downloads'), 'gateway' => edd_get_gateway_admin_label(get_post_meta($payment->ID, '_edd_payment_gateway', true)), 'trans_id' => $payment->transaction_id, 'key' => $payment_meta['key'], 'date' => $payment->date, 'user' => $user ? $user->display_name : __('guest', 'easy-digital-downloads'), 'currency' => $payment->currency, 'ip' => $payment->ip, 'mode' => $payment->get_meta('_edd_payment_mode', true), 'status' => 'publish' === $payment->status ? 'complete' : $payment->status); } $data = apply_filters('edd_export_get_data', $data); $data = apply_filters('edd_export_get_data_' . $this->export_type, $data); return $data; } return false; }
/** * Retrieve earning stats * * @access public * @since 1.8 * @param $download_id INT The download product to retrieve stats for. If false, gets stats for all products * @param $start_date string|bool 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 $end_date string|bool 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 $include_taxes bool If taxes should be included in the earnings graphs * @return float|int */ public function get_earnings($download_id = 0, $start_date = false, $end_date = false, $include_taxes = true) { global $wpdb; $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; } $earnings = false; add_filter('posts_where', array($this, 'payments_where')); if (empty($download_id)) { // Global earning stats $args = array('post_type' => 'edd_payment', 'nopaging' => true, 'post_status' => array('publish', 'revoked'), 'fields' => 'ids', 'update_post_term_cache' => false, 'suppress_filters' => false, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'edd_transient_type' => 'edd_earnings', 'include_taxes' => $include_taxes); $args = apply_filters('edd_stats_earnings_args', $args); $key = md5(serialize($args)); $earnings = get_transient($key); if (false === $earnings) { $sales = get_posts($args); $earnings = 0; if ($sales) { $sales = implode(',', array_map('intval', $sales)); if ($include_taxes) { $earnings += $wpdb->get_var("SELECT SUM(meta_value) FROM {$wpdb->postmeta} WHERE meta_key = '_edd_payment_total' AND post_id IN ({$sales})"); } else { $earnings_with_tax = $wpdb->get_var("SELECT SUM(meta_value) FROM {$wpdb->postmeta} WHERE meta_key = '_edd_payment_total' AND post_id IN ({$sales})"); $total_tax = $wpdb->get_var("SELECT SUM(meta_value) FROM {$wpdb->postmeta} WHERE meta_key = '_edd_payment_tax' AND post_id IN ({$sales})"); $earnings += $earnings_with_tax - $total_tax; } } // Cache the results for one hour set_transient($key, $earnings, 60 * 60); } } else { // Download specific earning stats global $edd_logs, $wpdb; $args = array('post_parent' => $download_id, 'nopaging' => true, 'log_type' => 'sale', 'fields' => 'ids', 'suppress_filters' => false, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'edd_transient_type' => 'edd_earnings', 'include_taxes' => $include_taxes); $args = apply_filters('edd_stats_earnings_args', $args); $key = md5(serialize($args)); $earnings = get_transient($key); if (false === $earnings) { $log_ids = $edd_logs->get_connected_logs($args, 'sale'); $earnings = 0; if ($log_ids) { $log_ids = implode(',', array_map('intval', $log_ids)); $payment_ids = $wpdb->get_col("SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_edd_log_payment_id' AND post_id IN ({$log_ids});"); foreach ($payment_ids as $payment_id) { $items = edd_get_payment_meta_cart_details($payment_id); foreach ($items as $item) { if ($item['id'] != $download_id) { continue; } $earnings += $item['price']; } if (!$include_taxes) { $earnings -= edd_get_payment_tax($payment_id); } } } // Cache the results for one hour set_transient($key, $earnings, 60 * 60); } } remove_filter('posts_where', array($this, 'payments_where')); return round($earnings, edd_currency_decimal_filter()); }
/** * Gets the sales tax for the current year * * @since 1.3.3 * @param $year int The year to retrieve taxes for, i.e. 2012 * @uses edd_get_payment_tax() * @return float $tax Sales tax */ function edd_get_sales_tax_for_year($year = null) { if (empty($year)) { return 0; } // Start at zero $tax = 0; $args = array('post_type' => 'edd_payment', 'posts_per_page' => -1, 'year' => $year, 'meta_key' => '_edd_payment_mode', 'meta_value' => edd_is_test_mode() ? 'test' : 'live', 'fields' => 'ids'); $payments = get_posts($args); if ($payments) { foreach ($payments as $payment) { $tax += edd_get_payment_tax($payment); } } return apply_filters('edd_get_sales_tax_for_year', $tax, $year); }
} ?> </span> </p> </div> <?php if (edd_use_taxes()) { ?> <div class="edd-order-taxes edd-admin-box-inside"> <p> <span class="label"><?php _e('Tax', 'edd'); ?> :</span> <input name="edd-payment-tax" type="number" step="0.01" class="small-text right " value="<?php echo esc_attr(edd_get_payment_tax($payment_id)); ?> "/> </p> </div> <?php } ?> <?php $fees = edd_get_payment_fees($payment_id); if (!empty($fees)) { ?> <div class="edd-order-fees edd-admin-box-inside"> <p class="strong"><?php _e('Fees', 'edd'); ?>
/** * Get the Export Data * * @access public * @since 1.4.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, $edd_options; $data = array(); $payments = edd_get_payments(array('offset' => 0, 'number' => -1, 'mode' => edd_is_test_mode() ? 'test' : 'live', 'status' => isset($_POST['edd_export_payment_status']) ? $_POST['edd_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) { // skip over payments that don't have upsells in them if (!get_post_meta($payment->ID, '_edd_payment_upsell_total', true)) { continue; } $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_csau_get_payment_amount($payment->ID, 'upsell'); $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) { // skip over downloads which aren't upsells if (!isset($download['item_number']['upsell'])) { continue; } // 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']) . ' - '; } } $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, 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'products' => $products, 'skus' => $skus, 'amount' => html_entity_decode(edd_format_amount($total)), 'tax' => html_entity_decode(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)), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'edd'), 'status' => edd_get_payment_status($payment, true)); if (!edd_use_skus()) { unset($data['skus']); } } $data = apply_filters('edd_export_get_data', $data); $data = apply_filters('edd_export_get_data_' . $this->export_type, $data); return $data; }
/** * Retrieve payments. * * The query can be modified in two ways; either the action before the * query is run, or the filter on the arguments (existing mainly for backwards * compatibility). * * @access public * @since 1.8 * @return object */ public function get_payments() { do_action('edd_pre_get_payments', $this); $query = new WP_Query($this->args); if ('payments' != $this->args['output']) { return $query->posts; } if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $details = new stdClass(); $payment_id = get_post()->ID; $details->ID = $payment_id; $details->date = get_post()->post_date; $details->post_status = get_post()->post_status; $details->total = edd_get_payment_amount($payment_id); $details->subtotal = edd_get_payment_subtotal($payment_id); $details->tax = edd_get_payment_tax($payment_id); $details->fees = edd_get_payment_fees($payment_id); $details->key = edd_get_payment_key($payment_id); $details->gateway = edd_get_payment_gateway($payment_id); $details->user_info = edd_get_payment_meta_user_info($payment_id); $details->cart_details = edd_get_payment_meta_cart_details($payment_id, true); if (edd_get_option('enable_sequential')) { $details->payment_number = edd_get_payment_number($payment_id); } $this->payments[] = apply_filters('edd_payment', $details, $payment_id, $this); } wp_reset_postdata(); } do_action('edd_post_get_payments', $this); return $this->payments; }
/** * 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; } }
/** * Upgrades payment taxes for 2.3 * * @since 2.3 * @return void */ function edd_v23_upgrade_payment_taxes() { global $wpdb; 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; $number = 50; $offset = $step == 1 ? 0 : ($step - 1) * $number; if ($step < 2) { // Check if we have any payments before moving on $sql = "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'edd_payment' LIMIT 1"; $has_payments = $wpdb->get_col($sql); if (empty($has_payments)) { // We had no payments, just complete update_option('edd_version', preg_replace('/[^0-9.].*/', '', EDD_VERSION)); edd_set_upgrade_complete('upgrade_payment_taxes'); delete_option('edd_doing_upgrade'); wp_redirect(admin_url()); exit; } } $total = isset($_GET['total']) ? absint($_GET['total']) : false; if (empty($total) || $total <= 1) { $total_sql = "SELECT COUNT(ID) as total_payments FROM {$wpdb->posts} WHERE post_type = 'edd_payment'"; $results = $wpdb->get_row($total_sql, 0); $total = $results->total_payments; } $payment_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'edd_payment' ORDER BY post_date DESC LIMIT %d,%d;", $offset, $number)); if ($payment_ids) { foreach ($payment_ids as $payment_id) { // Add the new _edd_payment_meta item $payment_tax = edd_get_payment_tax($payment_id); edd_update_payment_meta($payment_id, '_edd_payment_tax', $payment_tax); } // Payments found so upgrade them $step++; $redirect = add_query_arg(array('page' => 'edd-upgrades', 'edd-upgrade' => 'upgrade_payment_taxes', 'step' => $step, 'number' => $number, 'total' => $total), admin_url('index.php')); wp_redirect($redirect); exit; } else { // No more payments found, finish up update_option('edd_version', preg_replace('/[^0-9.].*/', '', EDD_VERSION)); edd_set_upgrade_complete('upgrade_payment_taxes'); delete_option('edd_doing_upgrade'); wp_redirect(admin_url()); exit; } }
</div> <?php } ?> <?php if (edd_use_taxes()) { ?> <div class="edd-order-taxes edd-admin-box-inside"> <p> <span class="label"><?php _e('Tax', 'edd'); ?> :</span> <input name="edd-payment-tax" class="med-text" type="text" value="<?php echo esc_attr(edd_format_amount(edd_get_payment_tax($payment_id))); ?> "/> </p> </div> <?php } ?> <div class="edd-order-payment edd-admin-box-inside"> <p> <span class="label"><?php _e('Total Price', 'edd'); ?> :</span> <?php
} else { _e('None', 'edd'); } ?> </span></p> </div> <?php $taxes = edd_use_taxes(); if ($taxes) { ?> <div class="edd-order-taxes edd-admin-box-inside"> <p><span class="label"><?php _e('Tax', 'edd'); ?> </span> <span class="right"><?php echo edd_currency_filter(edd_format_amount(edd_get_payment_tax($payment_id))); ?> </span></p> </div> <?php } ?> <?php $fees = edd_get_payment_fees($payment_id); if (!empty($fees)) { ?> <div class="edd-order-fees edd-admin-box-inside"> <p class="strong"><?php _e('Fees', 'edd'); ?> </p>