/** * 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; }
function sumobi_edd_customer_details_username($payment_id) { $user_info = edd_get_payment_meta_user_info($payment_id); $customer_id = $user_info['id']; if (!$customer_id) { return; } $user_data = get_userdata($customer_id); $user_name = $user_data->user_login; ?> <div class="column-container" style="margin-top: 20px;"> <div class="column"> <strong><?php _e('Username:'******'edd'); ?> </strong><br /> <a href="<?php echo get_edit_user_link($customer_id); ?> "><?php echo $user_name; ?> </a> </div> </div> <?php }
public function filter_reminder_template_tags($text = '', $license_id = 0) { $payment_id = get_post_meta($license_id, '_edd_sl_payment_id', true); $user_info = edd_get_payment_meta_user_info($payment_id); $user_id = edd_get_payment_user_id($payment_id); // Retrieve the customer name if ($user_id) { $user_data = get_userdata($user_id); $customer_name = $user_data->display_name; } elseif (isset($user_info['first_name'])) { $customer_name = $user_info['first_name']; } else { $customer_name = $user_info['email']; } $license_key = edd_software_licensing()->get_license_key($license_id); $download_id = get_post_meta($license_id, '_edd_sl_download_id', true); $product_name = get_the_title($download_id); $expiration = edd_software_licensing()->get_license_expiration($license_id); $expiration = date(get_option('date_format'), $expiration); $discount = edd_sl_get_renewal_discount_percentage($license_id); $renewal_link = apply_filters('edd_sl_renewal_link', edd_get_checkout_uri(array('edd_license_key' => $license_key, 'download_id' => $download_id))); $text = str_replace('{name}', $customer_name, $text); $text = str_replace('{license_key}', $license_key, $text); $text = str_replace('{product_name}', $product_name, $text); $text = str_replace('{expiration}', $expiration, $text); if (!empty($discount)) { $text = str_replace('{renewal_discount}', $discount . '%', $text); } $text = str_replace('{renewal_link}', $renewal_link, $text); return $text; }
/** * 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) { $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 = isset($payment_meta['amount']) ? $payment_meta['amount'] : 0.0; $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']) . ' - '; } } $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 the full HTML for the tickets email * * @param int $payment_id * * @return string */ public function get_content_html($payment_id = 0) { $user_info = edd_get_payment_meta_user_info($payment_id); $args = array('post_type' => Tribe__Tickets_Plus__Commerce__EDD__Main::$attendee_object, 'meta_key' => Tribe__Tickets_Plus__Commerce__EDD__Main::$attendee_order_key, 'meta_value' => $payment_id, 'posts_per_page' => -1, 'fields' => 'ids'); $query = new WP_Query($args); $attendees = array(); foreach ($query->posts as $ticket_id) { $attendees[] = array('event_id' => get_post_meta($ticket_id, Tribe__Tickets_Plus__Commerce__EDD__Main::$attendee_event_key, true), 'ticket_name' => get_post(get_post_meta($ticket_id, Tribe__Tickets_Plus__Commerce__EDD__Main::$attendee_product_key, true))->post_title, 'holder_name' => $user_info['first_name'] . ' ' . $user_info['last_name'], 'order_id' => $payment_id, 'ticket_id' => $ticket_id, 'security_code' => get_post_meta($ticket_id, Tribe__Tickets_Plus__Commerce__EDD__Main::$security_code, true)); } return Tribe__Tickets_Plus__Commerce__EDD__Main::get_instance()->generate_tickets_email_content($attendees); }
/** * Add points for purchase * * Handles to add points for purchases * * @package Easy Digital Downloads - Points and Rewards * @since 1.0.0 */ public function edd_points_add_point_for_complete_purchase($payment_id) { global $edd_options, $current_user; //get payment data $paymentdata = edd_get_payment_meta($payment_id); $userdata = edd_get_payment_meta_user_info($payment_id); $user_id = isset($userdata['id']) && !empty($userdata['id']) ? $userdata['id'] : 0; //get discount towards points $gotdiscount = $this->model->edd_points_get_payment_discount($payment_id); //check user has redeemed points or not & user_id should not empty if (isset($gotdiscount) && !empty($gotdiscount) && !empty($user_id)) { //get discounte price from points $discountedpoints = $this->model->edd_points_calculate_points($gotdiscount); //update user points edd_points_minus_points_from_user($discountedpoints, $user_id); //points label $pointslable = $this->model->edd_points_get_points_label($discountedpoints); //record data logs for redeem for purchase $post_data = array('post_title' => sprintf(__('Redeem %s for purchase', 'eddpoints'), $pointslable), 'post_content' => sprintf(__('%s redeemed for purchasing download by redeeming the points and get discounts.', 'eddpoints'), $pointslable), 'post_author' => $user_id); //log meta array $log_meta = array('userpoint' => $discountedpoints, 'events' => 'redeemed_purchase', 'operation' => 'minus'); //insert entry in log $this->logs->edd_points_insert_logs($post_data, $log_meta); // set order meta, regardless of whether any points were earned, just so we know the process took place update_post_meta($payment_id, '_edd_points_order_redeemed', $discountedpoints); } //end if to check points redeemed taken by buyer or not // get cartdata from older order $cartdata = edd_get_payment_meta_cart_details($payment_id); //get bought points for points downloads types $boughtpoints = $this->model->edd_points_get_bought_points($cartdata); //get cart points from cartdata and payment discount given to user $cartpoints = $this->model->edd_points_get_user_checkout_points($cartdata, $gotdiscount); //add bought points to cart points $cartpoints = !empty($boughtpoints) ? $cartpoints + $boughtpoints : $cartpoints; //check checkout points earned points or user id is not empty if (!empty($cartpoints) && !empty($user_id)) { //points label $pointslable = $this->model->edd_points_get_points_label($cartpoints); //get user points after subtracting the redemption points $userpoints = edd_points_get_user_points(); $post_data = array('post_title' => sprintf(__('%s earned for purchasing the downloads.', 'eddpoints'), $pointslable), 'post_content' => sprintf(__('Get %s for purchasing the downloads.', 'eddpoints'), $pointslable), 'post_author' => $user_id); $log_meta = array('userpoint' => $cartpoints, 'events' => 'earned_purchase', 'operation' => 'add'); //insert entry in log $this->logs->edd_points_insert_logs($post_data, $log_meta); //update user points edd_points_add_points_to_user($cartpoints, $user_id); // set order meta, regardless of whether any points were earned, just so we know the process took place update_post_meta($payment_id, '_edd_points_order_earned', $cartpoints); } //end if to check checkout points should not empty }
/** * 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; }
/** * Records referrals for the affiliate if a discount code belonging to the affiliate is used * * @access public * @since 1.1 */ public function track_discount_referral($payment_id = 0) { $user_info = edd_get_payment_meta_user_info($payment_id); if (isset($user_info['discount']) && $user_info['discount'] != 'none') { if (affiliate_wp()->settings->get('edd_disable_on_renewals')) { $was_renewal = get_post_meta($payment_id, '_edd_sl_is_renewal', true); if ($was_renewal) { return; } } $discounts = array_map('trim', explode(',', $user_info['discount'])); if (empty($discounts)) { return; } foreach ($discounts as $code) { $discount_id = edd_get_discount_id_by_code($code); $affiliate_id = get_post_meta($discount_id, 'affwp_discount_affiliate', true); if (!$affiliate_id) { continue; } $this->affiliate_id = $affiliate_id; if (!affiliate_wp()->tracking->is_valid_affiliate($this->affiliate_id)) { continue; } $existing = affiliate_wp()->referrals->get_by('reference', $payment_id, $this->context); // calculate the referral total $referral_total = $this->get_referral_total($payment_id, $this->affiliate_id); // referral already exists, update it if (!empty($existing->referral_id)) { // If a referral was already recorded, overwrite it with the linked discount affiliate affiliate_wp()->referrals->update($existing->referral_id, array('affiliate_id' => $this->affiliate_id, 'status' => 'unpaid', 'amount' => $referral_total), '', 'referral'); } else { // new referral if (0 == $referral_total && affiliate_wp()->settings->get('ignore_zero_referrals')) { return false; // Ignore a zero amount referral } $desc = $this->get_referral_description($payment_id); if (empty($desc)) { return false; } $referral_id = affiliate_wp()->referrals->add(array('amount' => $referral_total, 'reference' => $payment_id, 'description' => $desc, 'affiliate_id' => $this->affiliate_id, 'context' => $this->context, 'products' => $this->get_products($payment_id))); } } } }
/** * Track new users * * @since 1.0.0 * @param int $payment_id The ID of a given payment * @return void */ function edd_customerio_connect_register_user($payment_id) { // Bail if API isn't setup if (!edd_customerio_connect()->api) { return; } // Setup the request body $user_info = edd_get_payment_meta_user_info($payment_id); $payment_meta = edd_get_payment_meta($payment_id); $cart_items = isset($payment_meta['cart_details']) ? maybe_unserialize($payment_meta['cart_details']) : false; $user_name = false; if ($payment_meta['user_info']['first_name']) { $user_name = $payment_meta['user_info']['first_name']; if ($payment_meta['user_info']['last_name']) { $user_name .= ' ' . $payment_meta['user_info']['last_name']; } } $body = array('email' => $payment_meta['user_info']['email'], 'created_at' => $payment_meta['date']); if ($user_name) { $body['name'] = $user_name; } $response = edd_customerio_connect()->api->call($payment_meta['user_info']['id'], $body); // Track the purchases if (empty($cart_items) || !$cart_items) { $cart_items = maybe_unserialize($payment_meta['downloads']); } if ($cart_items) { $body = array('name' => 'purchased', 'data' => array('discount' => $payment_meta['user_info']['discount'])); foreach ($cart_items as $key => $cart_item) { $item_id = isset($payment_meta['cart_details']) ? $cart_item['id'] : $cart_item; $price = $cart_item['price']; $body['data']['items'][$cart_item['id']] = array('price' => $price, 'product_id' => $cart_item['id'], 'product_name' => esc_attr($cart_item['name'])); if (edd_has_variable_prices($cart_item['id'])) { $body['data']['items'][$cart_item['id']]['price_id'] = $cart_item['item_number']['options']['price_id']; $body['data']['items'][$cart_item['id']]['price_name'] = edd_get_price_option_name($cart_item['id'], $cart_item['item_number']['options']['price_id']); $body['data']['items'][$cart_item['id']]['quantity'] = $cart_item['item_number']['quantity']; } else { $body['data']['items'][$cart_item['id']]['quantity'] = $cart_item['quantity']; } if (edd_use_taxes()) { $body['data']['items'][$cart_item['id']]['tax'] = $cart_item['tax']; } } $response = edd_customerio_connect()->api->call($payment_meta['user_info']['id'], $body, 'POST', 'events'); } }
/** * After license activation, if is trial -- add to a list * * @used "edd_activate_license" */ public static function activate_license($data) { $license = !empty($data['license']) ? urldecode($data['license']) : false; $license_id = \EDD_Software_Licensing::instance()->get_license_by_key($license); $payment_id = get_post_meta($license_id, '_edd_sl_payment_id', true); $user_info = edd_get_payment_meta_user_info($payment_id); self::save_license_meta($data, $license_id, $user_info, $payment_id); $item_id = !empty($data['item_id']) ? absint($data['item_id']) : false; if (1 == 3 && class_exists('EDD_ConvertKit') && isset($data['details']['vertical']) && (self::$trial || ingSL::$trial == $item_id)) { self::$trial = true; $vertical = $data['details']['vertical']; if (!in_array($vertical, ingSL_verticals())) { return; } //$url = isset( $data[ 'url' ] ) ? urldecode( $data[ 'url' ] ) : ''; $convert_kit = new \EDD_ConvertKit(); $convert_kit->subscribe_email($user_info, $vertical, true); } }
/** * @param int $payment_id The ID of the payment * * @return bool|string */ public function subscribe_from_edd($payment_id) { if (!$this->triggered($payment_id)) { return false; } $email = (string) edd_get_payment_user_email($payment_id); $merge_vars = array(); // add first and last name to merge vars, if given $user_info = (array) edd_get_payment_meta_user_info($payment_id); if (isset($user_info['first_name']) && isset($user_info['last_name'])) { $merge_vars['NAME'] = $user_info['first_name'] . ' ' . $user_info['last_name']; } if (isset($user_info['first_name'])) { $merge_vars['FNAME'] = $user_info['first_name']; } if (isset($user_info['last_name'])) { $merge_vars['LNAME'] = $user_info['last_name']; } return $this->subscribe($email, $merge_vars, $payment_id); }
/** * @param int $payment_id The ID of the payment * * @return bool|string */ public function subscribe_from_edd($payment_id) { if (!$this->triggered($payment_id)) { return false; } $email = (string) edd_get_payment_user_email($payment_id); $data = array('EMAIL' => $email); // add first and last name to merge vars, if given $user_info = (array) edd_get_payment_meta_user_info($payment_id); if (!empty($user_info['first_name']) && !empty($user_info['last_name'])) { $data['NAME'] = $user_info['first_name'] . ' ' . $user_info['last_name']; } if (!empty($user_info['first_name'])) { $data['FNAME'] = $user_info['first_name']; } if (!empty($user_info['last_name'])) { $data['LNAME'] = $user_info['last_name']; } return $this->subscribe($data, $payment_id); }
/** * @param int $payment_id The ID of the payment * * @return bool|string */ public function subscribe_from_edd_purchase($payment_id) { $meta = get_post_meta($payment_id, '_yikes_easy_mc_optin', true); if ($meta == '0') { return false; } $email = (string) edd_get_payment_user_email($payment_id); $merge_vars = array(); // add first and last name to merge vars, if given $user_info = (array) edd_get_payment_meta_user_info($payment_id); if (isset($user_info['first_name']) && isset($user_info['last_name'])) { $merge_vars['NAME'] = $user_info['first_name'] . ' ' . $user_info['last_name']; } if (isset($user_info['first_name'])) { $merge_vars['FNAME'] = $user_info['first_name']; } if (isset($user_info['last_name'])) { $merge_vars['LNAME'] = $user_info['last_name']; } // subscribe the user $this->subscribe_user_integration(sanitize_email($email), $this->type, $merge_vars); }
/** * Receipt Shortcode * * Shows an order receipt. * * @since 1.4 * @param array $atts Shortcode attributes * @param string $content * @return string */ function edd_receipt_shortcode($atts, $content = null) { global $edd_receipt_args; $edd_receipt_args = shortcode_atts(array('error' => __('Sorry, trouble retrieving payment receipt.', 'edd'), 'price' => true, 'discount' => true, 'products' => true, 'date' => true, 'notes' => true, 'payment_key' => true, 'payment_method' => true, 'payment_id' => true), $atts); $session = edd_get_purchase_session(); if (isset($_GET['purchase_key'])) { $purchase_key = urldecode($_GET['purchase_key']); } else { if ($session) { $purchase_key = $session['purchase_key']; } } // No key found if (!isset($purchase_key)) { return $edd_receipt_args['error']; } $edd_receipt_args['id'] = edd_get_purchase_id_by_key($purchase_key); $user = edd_get_payment_meta_user_info($edd_receipt_args['id']); // Not the proper user if (is_user_logged_in() && $user['id'] != get_current_user_id()) { return $edd_receipt_args['error']; } ob_start(); edd_get_template_part('shortcode', 'receipt'); $display = ob_get_clean(); return $display; }
/** * Flushes the current user's purchase history transient when a payment status * is updated * * @since 1.2.2 * * @param $payment_id * @param $new_status the status of the payment, probably "publish" * @param $old_status the status of the payment prior to being marked as "complete", probably "pending" */ function edd_clear_user_history_cache($payment_id, $new_status, $old_status) { $user_info = edd_get_payment_meta_user_info($payment_id); delete_transient('edd_user_' . $user_info['id'] . '_purchases'); }
function remote_license_check($data) { $item_id = !empty($data['item_id']) ? absint($data['item_id']) : false; $item_name = !empty($data['item_name']) ? rawurldecode($data['item_name']) : false; $license = urldecode($data['license']); $url = isset($data['url']) ? urldecode($data['url']) : ''; $license_id = self::get_license_by_key($license); $expires = self::get_license_expiration($license_id); $payment_id = get_post_meta($license_id, '_edd_sl_payment_id', true); $user_info = edd_get_payment_meta_user_info($payment_id); $download_id = get_post_meta($license_id, '_edd_sl_download_id', true); $args = array('item_id' => $item_id, 'item_name' => $item_name, 'key' => $license, 'url' => $url); $result = self::check_license($args); $license_limit = self::get_license_limit($download_id, $license_id); $site_count = self::get_site_count($license_id); if (empty($item_name)) { $item_name = get_the_title($item_id); } header('Content-Type: application/json'); echo json_encode(apply_filters('edd_remote_license_check_response', array('success' => (bool) $result, 'license' => $result, 'item_name' => $item_name, 'expires' => is_numeric($expires) ? date('Y-m-d H:i:s', $expires) : $expires, 'payment_id' => $payment_id, 'customer_name' => $user_info['first_name'] . ' ' . $user_info['last_name'], 'customer_email' => $user_info['email'], 'license_limit' => $license_limit, 'site_count' => $site_count, 'activations_left' => $license_limit > 0 ? $license_limit - $site_count : 'unlimited'), $args, $license_id)); exit; }
/** * 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; } }
/** * 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; }
public function order_list_customer($order_id) { $customer = edd_get_payment_meta_user_info($order_id); $customer_name = $customer['first_name'] . ' ' . $customer['last_name']; $customer_name = apply_filters('fes_order_list_customer', $customer_name, $customer); return $customer_name; }
/** * 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; }
/** * Add the shipping address to the end of the payment receipt. * * @since 2.0 * * @param object $payment * @param array $edd_receipt_args * @return void */ public function payment_receipt_after($payment, $edd_receipt_args) { $user_info = edd_get_payment_meta_user_info($payment->ID); $address = !empty($user_info['shipping_info']) ? $user_info['shipping_info'] : false; if (!$address) { return; } $shipped = get_post_meta($payment->ID, '_edd_payment_shipping_status', true); if ($shipped == '2') { $new_status = '1'; } else { $new_status = '2'; } $toggle_url = esc_url(add_query_arg(array('edd_action' => 'toggle_shipped_status', 'order_id' => $payment->ID, 'new_status' => $new_status))); $toggle_text = $shipped == '2' ? __('Mark as not shipped', 'edd-simple-shipping') : __('Mark as shipped', 'edd-simple-shipping'); echo '<tr>'; echo '<td><strong>' . __('Shipping Address', 'edd-simple-shipping') . '</strong></td>'; echo '<td>' . self::format_address($user_info, $address) . '<td>'; echo '</tr>'; if (current_user_can('edit_shop_payments') || current_user_can('frontend_vendor')) { echo '<tr>'; echo '<td colspan="2">'; echo '<a href="' . $toggle_url . '" class="edd-simple-shipping-toggle-status">' . $toggle_text . '</a>'; echo '</td>'; echo '</tr>'; } }
/** * Email template tag: discount_codes * Adds a list of any discount codes applied to this purchase * * @since 2.0 * @param $int payment_id * @return string $discount_codes */ function edd_email_tag_discount_codes($payment_id) { $user_info = edd_get_payment_meta_user_info($payment_id); $discount_codes = ''; if (isset($user_info['discount']) && $user_info['discount'] !== 'none') { $discount_codes = $user_info['discount']; } return $discount_codes; }
/** * Gets the log entries for the current view * * @access private * @since 1.4 * @return array */ function get_logs() { global $edd_logs; $logs_data = array(); $paged = $this->get_paged(); $log_query = array('log_type' => 'gateway_error', 'paged' => $paged); $logs = $edd_logs->get_connected_logs($log_query); if ($logs) { foreach ($logs as $log) { $user_info = edd_get_payment_meta_user_info($log->post_parent); $user_id = isset($user_info['id']) ? $user_info['id'] : 0; $user_data = get_userdata($user_id); $logs_data[] = array('ID' => $log->ID, 'payment_id' => $log->post_parent, 'error' => 'error', 'gateway' => 'gateway', 'user_id' => $user_id, 'buyer' => $user_data ? $user_data->display_name : $user_info['email'], 'date' => $log->post_date); } } return $logs_data; }
/** * Render the print ticket view, based on the email template * * @return void */ public function render_ticket_print_view() { // Is this a print-ticket request? if (!isset($_GET['eddfile']) || !isset($_GET['edd_action']) || $_GET['edd_action'] !== 'print_ticket') { return; } // As of EDD 2.3 a token should be available to help verify if the link is valid if (!$this->passed_token_validation($_GET)) { return; } // Decompile the eddfile argument into its base components $order_parts = array_values(explode(':', rawurldecode($_GET['eddfile']))); // We expect there to be at least two components (payment and download IDs) if (count($order_parts) < 2) { return; } $payment_id = $order_parts[0]; $download_id = $order_parts[1]; $user_info = edd_get_payment_meta_user_info($payment_id); $args = array('post_type' => self::ATTENDEE_OBJECT, 'meta_query' => array(array('key' => self::ATTENDEE_ORDER_KEY, 'value' => $payment_id), array('key' => self::ATTENDEE_PRODUCT_KEY, 'value' => $download_id)), 'posts_per_page' => -1, 'fields' => 'ids'); $query = new WP_Query($args); $attendees = array(); foreach ($query->posts as $ticket_id) { $attendees[] = array('event_id' => get_post_meta($ticket_id, self::ATTENDEE_EVENT_KEY, true), 'ticket_name' => get_post(get_post_meta($ticket_id, self::ATTENDEE_PRODUCT_KEY, true))->post_title, 'holder_name' => $user_info['first_name'] . ' ' . $user_info['last_name'], 'order_id' => $payment_id, 'ticket_id' => $ticket_id, 'security_code' => get_post_meta($ticket_id, self::$security_code, true)); } $content = self::get_instance()->generate_tickets_email_content($attendees); $content .= '<script type="text/javascript">window.onload = function(){ window.print(); }</script>'; echo $content; exit; }
// Setup the variables $payment_id = absint($_GET['id']); $number = edd_get_payment_number($payment_id); $item = get_post($payment_id); // Sanity check... fail if purchase ID is invalid if (!is_object($item) || $item->post_type != 'edd_payment') { wp_die(__('The specified ID does not belong to a payment. Please try again', 'edd'), __('Error', 'edd')); } $payment_meta = edd_get_payment_meta($payment_id); $transaction_id = esc_attr(edd_get_payment_transaction_id($payment_id)); $cart_items = edd_get_payment_meta_cart_details($payment_id); $user_id = edd_get_payment_user_id($payment_id); $customer_id = edd_get_payment_customer_id($payment_id); $payment_date = strtotime($item->post_date); $unlimited = edd_payment_has_unlimited_downloads($payment_id); $user_info = edd_get_payment_meta_user_info($payment_id); $address = !empty($user_info['address']) ? $user_info['address'] : array('line1' => '', 'line2' => '', 'city' => '', 'country' => '', 'state' => '', 'zip' => ''); $gateway = edd_get_payment_gateway($payment_id); $currency_code = edd_get_payment_currency_code($payment_id); ?> <div class="wrap edd-wrap"> <h2><?php printf(__('Payment %s', 'edd'), $number); ?> </h2> <?php do_action('edd_view_order_details_before', $payment_id); ?> <form id="edd-edit-order-form" method="post"> <?php do_action('edd_view_order_details_form_top', $payment_id);
/** * Undos a purchase, including the decrease of sale and earning stats. Used for * when refunding or deleting a purchase * * @since 1.0.8.1 * @param int $download_id Download (Post) ID * @param int $payment_id Payment ID * @return void */ function edd_undo_purchase($download_id, $payment_id) { $cart_details = edd_get_payment_meta_cart_details($payment_id); $user_info = edd_get_payment_meta_user_info($payment_id); if (is_array($cart_details)) { foreach ($cart_details as $item) { // get the item's price $amount = isset($item['price']) ? $item['price'] : false; // Decrease earnings/sales and fire action once per quantity number for ($i = 0; $i < $item['quantity']; $i++) { // variable priced downloads if (false === $amount && edd_has_variable_prices($download_id)) { $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; $amount = !isset($item['price']) && 0 !== $item['price'] ? edd_get_price_option_amount($download_id, $price_id) : $item['price']; } if (!$amount) { // This function is only used on payments with near 1.0 cart data structure $amount = edd_get_download_final_price($download_id, $user_info, $amount); } } // decrease earnings edd_decrease_earnings($download_id, $amount); // decrease purchase count edd_decrease_purchase_count($download_id, $item['quantity']); } } }
/** * 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: billing_address * The buyer's billing address * * @since 1.0.0 * @param int $payment_id * @return string billing_address */ function edd_wallet_email_tag_billing_address($payment_id) { if (get_post_type($payment_id) == 'edd_payment') { $user_info = edd_get_payment_meta_user_info($payment_id); $user_address = !empty($user_info['address']) ? $user_info['address'] : array('line1' => '', 'line2' => '', 'city' => '', 'country' => '', 'state' => '', 'zip' => ''); $return = $user_address['line1'] . "\n"; if (!empty($user_address['line2'])) { $return .= $user_address['line2'] . "\n"; } $return .= $user_address['city'] . ' ' . $user_address['zip'] . ' ' . $user_address['state'] . "\n"; $return .= $user_address['country']; return $return; } else { return ''; } }
$payment = get_post($edd_receipt_args['id']); if (empty($payment)) { ?> <div class="edd_errors edd-alert edd-alert-error"> <?php _e('The specified receipt ID appears to be invalid', 'easy-digital-downloads'); ?> </div> <?php return; } $meta = edd_get_payment_meta($payment->ID); $cart = edd_get_payment_meta_cart_details($payment->ID, true); $user = edd_get_payment_meta_user_info($payment->ID); $email = edd_get_payment_user_email($payment->ID); $status = edd_get_payment_status($payment, true); ?> <table id="edd_purchase_receipt"> <thead> <?php do_action('edd_payment_receipt_before', $payment, $edd_receipt_args); ?> <?php if ($edd_receipt_args['payment_id']) { ?> <tr> <th><strong><?php _e('Payment', 'easy-digital-downloads');
/** * Check if a customer needs to be subscribed on completed purchase of specific products */ public function completed_download_purchase_signup($download_id = 0, $payment_id = 0, $download_type = 'default') { $user_info = edd_get_payment_meta_user_info($payment_id); $lists = get_post_meta($download_id, '_edd_' . $this->id, true); if ('bundle' == $download_type) { // Get the lists of all items included in the bundle $downloads = edd_get_bundled_products($download_id); if ($downloads) { foreach ($downloads as $d_id) { $d_lists = get_post_meta($d_id, '_edd_' . $this->id, true); if (is_array($d_lists)) { $lists = array_merge($d_lists, (array) $lists); } } } } if (empty($lists)) { return; } $lists = array_unique($lists); foreach ($lists as $list) { $this->subscribe_email($user_info, $list); } }