/** * Sale price field. * * Display the simple sale price field below the normal price field. * * @since 1.0.0 * * @param int $post_id ID of the current download being edited. */ public function simple_sale_price_field($post_id) { $price = edd_get_download_price($post_id); $sale_price = get_post_meta($post_id, 'edd_sale_price', true); $variable_pricing = edd_has_variable_prices($post_id); $prices = edd_get_variable_prices($post_id); $single_option_mode = edd_single_price_option_mode($post_id); $price_display = $variable_pricing ? ' style="display:none;"' : ''; $variable_display = $variable_pricing ? '' : ' style="display:none;"'; ?> <div id="edd_regular_sale_price_field" class="edd_pricing_fields" <?php echo $price_display; ?> ><?php $price_args = array('name' => 'edd_sale_price', 'value' => !empty($sale_price) ? esc_attr(edd_format_amount($sale_price)) : '', 'class' => 'edd-price-field edd-sale-price-field'); $currency_position = edd_get_option('currency_position'); if (empty($currency_position) || $currency_position == 'before') { echo edd_currency_filter('') . ' ' . EDD()->html->text($price_args) . ' '; } else { echo EDD()->html->text($price_args) . ' ' . edd_currency_filter('') . ' '; } ?> <label class="edd-label" for="edd_sale_price"><?php _e('Sale price', 'edd-sale-price'); ?> </label> <?php ?> </div><?php }
/** * Check for download price variations * * @since 2.0 * @return void */ function edd_cr_check_for_download_price_variations() { if (!current_user_can('edit_products')) { die('-1'); } $download_id = absint($_POST['download_id']); $key = isset($_POST['key']) ? absint($_POST['key']) : 0; $download = get_post($download_id); if ('download' != $download->post_type) { die('-2'); } if (edd_has_variable_prices($download_id)) { $variable_prices = edd_get_variable_prices($download_id); if ($variable_prices) { $ajax_response = '<select class="edd_price_options_select edd-select edd-select edd_cr_download" name="edd_cr_download[' . $key . '][price_id]">'; $ajax_response .= '<option value="all">' . esc_html(__('All prices', 'edd-cr')) . '</option>'; foreach ($variable_prices as $price_id => $price) { $ajax_response .= '<option value="' . esc_attr($price_id) . '">' . esc_html($price['name']) . '</option>'; } $ajax_response .= '</select>'; echo $ajax_response; } } edd_die(); }
/** * Increment the backer count for every download in this payment. * * @param int $payment_id * @param string $direction * @return void * @since 0.9 */ function atcf_update_backer_count($payment_id, $direction) { $payment_data = edd_get_payment_meta($payment_id); $downloads = maybe_unserialize($payment_data['downloads']); if (!is_array($downloads)) { return; } foreach ($downloads as $download) { $variable_pricing = edd_get_variable_prices($download['id']); foreach ($variable_pricing as $key => $value) { $what = isset($download['options']['price_id']) ? intval($download['options']['price_id']) : 0; if (!isset($variable_pricing[$what]['bought'])) { $variable_pricing[$what]['bought'] = 0; } $current = $variable_pricing[$what]['bought']; if ($key == $what) { if ('increase' == $direction) { $variable_pricing[$what]['bought'] = $current + $download['quantity']; } else { $variable_pricing[$what]['bought'] = $current - $download['quantity']; } } } update_post_meta($download['id'], 'edd_variable_prices', $variable_pricing); } }
function if_download_price_function($atts, $content) { $atts = shortcode_atts(array('not' => 'no', 'id' => '', 'equals' => '', 'greater' => '', 'less' => ''), $atts, 'if_download_price'); if ($atts['id'] != '') { $id = $atts['id']; } else { $id = get_the_id(); } ob_start(); $price = ''; if (edd_has_variable_prices($id)) { $get_default_price = edd_get_default_variable_price($id); $prices = edd_get_variable_prices($id); $price = $prices[$get_default_price]['amount']; } else { $price = edd_get_download_price($id); } if ($atts['not'] == 'yes' || $atts['not'] == '1') { if (!eval_condition($price, $atts['equals'], $atts['greater'], $atts['less'])) { echo do_shortcode($content); } else { echo ''; } } else { if (eval_condition($price, $atts['equals'], $atts['greater'], $atts['less'])) { echo do_shortcode($content); } else { echo ''; } } return ob_get_clean(); }
/** * make sure the last option in array is checked (highest priced item) */ function sumobi_edd_price_option_checked($checked, $download_id, $key) { $prices = edd_get_variable_prices($download_id); end($prices); $checked = key($prices); return $checked; }
/** * Setup the variable and prices properties * * @since 0.0.9 * * @access protected */ protected function set_price() { if (edd_has_variable_prices($this->product->ID)) { $this->variable = true; $this->prices = edd_get_variable_prices($this->product->ID); } else { $this->variable = false; $this->prices = edd_get_download_price($this->product->ID); } }
function atcf_purchase_variable_pricing($download_id) { $variable_pricing = edd_has_variable_prices($download_id); if (!$variable_pricing) { return; } $prices = edd_get_variable_prices($download_id); $type = edd_single_price_option_mode($download_id) ? 'checkbox' : 'radio'; do_action('edd_before_price_options', $download_id); do_action('atcf_campaign_contribute_options', $prices, $type, $download_id); do_action('edd_after_price_options', $download_id); }
function download_add_to_cart_function($atts, $content) { $atts = shortcode_atts(array('id' => '', 'style' => 'button', 'option' => '', 'price' => '1', 'text' => 'Add to Cart', 'color' => '', 'class' => '', 'direct' => '', 'show' => ''), $atts, 'download_url_addtocart'); if ($atts['id'] != '') { $download_id = $atts['id']; } else { $download_id = get_the_ID(); } global $post, $download_loop, $current_price, $global_checkout_price_id; $external = get_post_meta($download_id, '_edd_external_url', true); if (isset($external) && $external != '' && $atts['show'] != 'button') { return $external; } if (isset($global_checkout_price_id) && $global_checkout_price_id != '' && $global_checkout_price_id != null) { $price_id = $global_checkout_price_id; } else { if (isset($current_price) && $current_price != '' && $current_price != null) { $price_id = $current_price['price_id']; } else { if (edd_has_variable_prices($download_id)) { $price_id = edd_get_default_variable_price($download_id); } } } if ($atts['option'] > 0) { $price_list_temp = edd_get_variable_prices($download_id); if (array_key_exists($atts['option'], $price_list_temp)) { $price_id = $atts['option']; } } if (edd_has_variable_prices($download_id) && $atts['option'] != 'list') { if ($atts['show'] != 'url') { $content = '[purchase_link class="blue edd-submit ' . $atts['class'] . '" color="' . $atts['color'] . '" direct="' . $atts['direct'] . '" price="' . $atts['price'] . '" text="' . $atts['text'] . '" id="' . $download_id . '" price_id="' . $price_id . '" style="' . $atts['style'] . '" ]'; return do_shortcode($content); } else { return site_url() . "?edd_action=add_to_cart&download_id={$download_id}&edd_options[price_id]={$price_id}"; } } else { if ($atts['show'] != 'url') { return do_shortcode('[purchase_link class=" blue edd-submit ' . $atts['class'] . '" color="' . $atts['color'] . '" direct="' . $atts['direct'] . '" price="' . $atts['price'] . '" text="' . $atts['text'] . '" id="' . $download_id . '" style="' . $atts['style'] . '" ]'); } else { return site_url() . "?edd_action=add_to_cart&download_id={$download_id}"; } } }
/** * Get final price of a download after discount * * Modified From: * includes/download-functions.php -> edd_price() * Modified Parts: * Remove the price as a number, without the html formatting. * * @param int $download_id ID of the download * @return float Download price */ function vp_edd_fd_get_calculated_price($download_id) { if (edd_has_variable_prices($download_id)) { $prices = edd_get_variable_prices($download_id); // Return the lowest price $price_float = 0; foreach ($prices as $key => $value) { if ((double) $prices[$key]['amount'] < $price_float or $price_float == 0) { $price_float = (double) $prices[$key]['amount']; } } $price = edd_sanitize_amount($price_float); } else { $price = edd_get_download_price($download_id); } if (edd_use_taxes() && edd_taxes_on_prices()) { $price += edd_calculate_tax($price); } return $price; }
function shoestrap_edd_purchase_variable_pricing($download_id) { $variable_pricing = edd_has_variable_prices($download_id); if (!$variable_pricing) { return; } $prices = apply_filters('edd_purchase_variable_prices', edd_get_variable_prices($download_id), $download_id); $type = edd_single_price_option_mode($download_id) ? 'checkbox' : 'radio'; do_action('edd_before_price_options', $download_id); echo '<div class="edd_price_options">'; if ($prices) { echo '<select name="edd_options[price_id][]">'; foreach ($prices as $key => $price) { printf('<option for="%3$s" name="edd_options[price_id][]" id="%3$s" class="%4$s" value="%5$s" %7$s> %6$s</option>', checked(0, $key, false), $type, esc_attr('edd_price_option_' . $download_id . '_' . $key), esc_attr('edd_price_option_' . $download_id), esc_attr($key), esc_html($price['name'] . ' - ' . edd_currency_filter(edd_format_amount($price['amount']))), selected(isset($_GET['price_option']), $key, false)); do_action('edd_after_price_option', $key, $price, $download_id); } echo '</select>'; } do_action('edd_after_price_options_list', $download_id, $prices, $type); echo '</div><!--end .edd_price_options-->'; do_action('edd_after_price_options', $download_id); }
* License: */ defined('ABSPATH') or die("No script kiddies please!"); function edd_plans_load_multiple_license() { wp_enqueue_script('edd_plans_multiple_license', plugins_url() . '/edd_plans/helpers/edd_plans.js', 'jquery', '', true); } function edd_plans_multiple_license_row($key, $args = array(), $post_id) { $edd_plans_multiple_license = get_post_meta($post_id, 'edd_plans_multiple_license', true); $length_default = isset($edd_plans_multiple_license[$key]['length']) ? $edd_plans_multiple_license[$key]['length'] : ''; $unit_default = isset($edd_plans_multiple_license[$key]['unit']) ? $edd_plans_multiple_license[$key]['unit'] : ''; $variable_pricing = edd_has_variable_prices($post_id); if ($variable_pricing) { $prices = edd_get_variable_prices($post_id); } else { $prices = edd_get_download_price($post_id); } $enabled = isset($prices[$key]['renew']) ? true : false; echo '<td>';
/** * Maybe add incentive discounts * * @since 1.0.1 * @param float $discount The current discount amount * @param array $item The cart item array * @return float $discount The updated discount amount */ function edd_wallet_item_incentive_amount($discount, $item) { $incentive_amount = edd_get_option('edd_wallet_incentive_amount', 0); if ($incentive_amount <= 0) { return $discount; } if (!EDD()->session->get('wallet_has_incentives')) { return $discount; } if (edd_has_variable_prices($item['id'])) { $prices = edd_get_variable_prices($item['id']); $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : 0; if ($price_id !== false && $price_id !== '' && isset($prices[$price_id])) { $price = edd_get_price_option_amount($item['id'], $price_id); } else { $price = edd_get_lowest_price_option($item['id']); } } else { $price = edd_get_download_price($item['id']); } $incentive_type = edd_get_option('edd_wallet_incentive_type', 'flatrate'); if ($incentive_type == 'percent') { $incentive_amount /= 100; $incentive_amount = $price * $incentive_amount; if (edd_item_quantities_enabled() && edd_get_option('edd_wallet_incentive_quantities', false)) { $incentive_amount *= $item['quantity']; } $incentive_amount = number_format($incentive_amount, 2, '.', ''); } else { if (edd_item_quantities_enabled() && edd_get_option('edd_wallet_incentive_quantities', false)) { $incentive_amount *= $item['quantity']; } } $discount += $incentive_amount; return $discount; }
/** * Generate PDF Reports * * Generates PDF report on sales and earnings for all downloads for the current year. * * @since 1.1.4.0 * @param string $data * @uses edd_pdf * @author Sunny Ratilal */ function edd_generate_pdf($data) { $edd_pdf_reports_nonce = $_GET['_wpnonce']; if (wp_verify_nonce($edd_pdf_reports_nonce, 'edd_generate_pdf')) { require_once EDD_PLUGIN_DIR . '/includes/libraries/fpdf/fpdf.php'; require_once EDD_PLUGIN_DIR . '/includes/libraries/fpdf/edd_pdf.php'; $daterange = date_i18n(get_option('date_format'), mktime(0, 0, 0, 1, 1, date('Y'))) . ' ' . utf8_decode(__('to', 'edd')) . ' ' . date_i18n(get_option('date_format')); $pdf = new edd_pdf(); $pdf->AddPage('L', 'A4'); $pdf->SetTitle(utf8_decode(__('Sales and earnings reports for the current year for all products', 'edd'))); $pdf->SetAuthor(utf8_decode(__('Easy Digital Downloads', 'edd'))); $pdf->SetCreator(utf8_decode(__('Easy Digital Downloads', 'edd'))); $pdf->Image(EDD_PLUGIN_URL . 'assets/images/edd-logo.png', 205, 10); $pdf->SetMargins(8, 8, 8); $pdf->SetX(8); $pdf->SetFont('Helvetica', '', 16); $pdf->SetTextColor(50, 50, 50); $pdf->Cell(0, 3, utf8_decode(__('Sales and earnings reports for the current year for all products', 'edd')), 0, 2, 'L', false); $pdf->SetFont('Helvetica', '', 13); $pdf->Ln(); $pdf->SetTextColor(150, 150, 150); $pdf->Cell(0, 6, utf8_decode(__('Date Range: ', 'edd')) . $daterange, 0, 2, 'L', false); $pdf->Ln(); $pdf->SetTextColor(50, 50, 50); $pdf->SetFont('Helvetica', '', 14); $pdf->Cell(0, 10, utf8_decode(__('Table View', 'edd')), 0, 2, 'L', false); $pdf->SetFont('Helvetica', '', 12); $pdf->SetFillColor(238, 238, 238); $pdf->Cell(70, 6, utf8_decode(__('Product Name', 'edd')), 1, 0, 'L', true); $pdf->Cell(30, 6, utf8_decode(__('Price', 'edd')), 1, 0, 'L', true); $pdf->Cell(50, 6, utf8_decode(__('Categories', 'edd')), 1, 0, 'L', true); $pdf->Cell(50, 6, utf8_decode(__('Tags', 'edd')), 1, 0, 'L', true); $pdf->Cell(45, 6, utf8_decode(__('Number of Sales', 'edd')), 1, 0, 'L', true); $pdf->Cell(35, 6, utf8_decode(__('Earnings to Date', 'edd')), 1, 1, 'L', true); $year = date('Y'); $downloads = get_posts(array('post_type' => 'download', 'year' => $year, 'posts_per_page' => -1)); if ($downloads) { $pdf->SetWidths(array(70, 30, 50, 50, 45, 35)); foreach ($downloads as $download) { $pdf->SetFillColor(255, 255, 255); $title = utf8_decode(get_the_title($download->ID)); if (edd_has_variable_prices($download->ID)) { $prices = edd_get_variable_prices($download->ID); $first = $prices[0]['amount']; $last = array_pop($prices); $last = $last['amount']; if ($first < $last) { $min = $first; $max = $last; } else { $min = $last; $max = $first; } $price = html_entity_decode(edd_currency_filter(edd_format_amount($min)) . ' - ' . edd_currency_filter(edd_format_amount($max))); } else { $price = html_entity_decode(edd_currency_filter(edd_get_download_price($download->ID))); } $categories = get_the_term_list($download->ID, 'download_category', '', ', ', ''); $categories = $categories ? strip_tags($categories) : ''; $tags = get_the_term_list($download->ID, 'download_tag', '', ', ', ''); $tags = $tags ? strip_tags($tags) : ''; $sales = edd_get_download_sales_stats($download->ID); $link = get_permalink($download->ID); $earnings = html_entity_decode(edd_currency_filter(edd_get_download_earnings_stats($download->ID))); $pdf->Row(array($title, $price, $categories, $tags, $sales, $earnings)); } } else { $pdf->SetWidths(array(280)); $title = utf8_decode(sprintf(__('No %s found.', 'edd'), edd_get_label_plural())); $pdf->Row(array($title)); } $pdf->Ln(); $pdf->SetTextColor(50, 50, 50); $pdf->SetFont('Helvetica', '', 14); $pdf->Cell(0, 10, utf8_decode(__('Graph View', 'edd')), 0, 2, 'L', false); $pdf->SetFont('Helvetica', '', 12); $image = html_entity_decode(urldecode(edd_draw_chart_image())); $image = str_replace(' ', '%20', $image); $pdf->SetX(25); $pdf->Image($image . '&file=.png'); $pdf->Ln(7); $pdf->Output('edd-report-' . date_i18n('Y-m-d') . '.pdf', 'D'); } }
function get_price_is_lifetime($download_id = 0, $price_id = null) { $prices = edd_get_variable_prices($download_id); if (!empty($prices[$price_id]['is_lifetime'])) { return true; } return false; }
/** * Given a download post object, generate the data for the API output * * @since 2.3.9 * @param object $product_info The Download Post Object * @return array Array of post data to return back in the API */ private function get_product_data($product_info) { $product = array(); $product['info']['id'] = $product_info->ID; $product['info']['slug'] = $product_info->post_name; $product['info']['title'] = $product_info->post_title; $product['info']['create_date'] = $product_info->post_date; $product['info']['modified_date'] = $product_info->post_modified; $product['info']['status'] = $product_info->post_status; $product['info']['link'] = html_entity_decode($product_info->guid); $product['info']['content'] = $product_info->post_content; $product['info']['excerpt'] = $product_info->post_excerpt; $product['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($product_info->ID)); $product['info']['category'] = get_the_terms($product_info, 'download_category'); $product['info']['tags'] = get_the_terms($product_info, 'download_tag'); if (user_can($this->user_id, 'view_shop_reports') || $this->override) { $product['stats']['total']['sales'] = edd_get_download_sales_stats($product_info->ID); $product['stats']['total']['earnings'] = edd_get_download_earnings_stats($product_info->ID); $product['stats']['monthly_average']['sales'] = edd_get_average_monthly_download_sales($product_info->ID); $product['stats']['monthly_average']['earnings'] = edd_get_average_monthly_download_earnings($product_info->ID); } if (edd_has_variable_prices($product_info->ID)) { foreach (edd_get_variable_prices($product_info->ID) as $price) { $product['pricing'][sanitize_key($price['name'])] = $price['amount']; } } else { $product['pricing']['amount'] = edd_get_download_price($product_info->ID); } if (user_can($this->user_id, 'view_shop_sensitive_data') || $this->override) { foreach (edd_get_download_files($product_info->ID) as $file) { $product['files'][] = $file; } $product['notes'] = edd_get_product_notes($product_info->ID); } return apply_filters('edd_api_products_product', $product); }
/** * Variable price output * * Outputs variable pricing options for each download or a specified downloads in a list. * The output generated can be overridden by the filters provided or by removing * the action and adding your own custom action. * * @since 1.2.3 * @param int $download_id Download ID * @return void */ function edd_purchase_variable_pricing($download_id = 0, $args = array()) { $variable_pricing = edd_has_variable_prices($download_id); if (!$variable_pricing) { return; } $prices = apply_filters('edd_purchase_variable_prices', edd_get_variable_prices($download_id), $download_id); // If the price_id passed is found in the variable prices, do not display all variable prices. if (false !== $args['price_id'] && isset($prices[$args['price_id']])) { return; } $type = edd_single_price_option_mode($download_id) ? 'checkbox' : 'radio'; $mode = edd_single_price_option_mode($download_id) ? 'multi' : 'single'; $schema = edd_add_schema_microdata() ? ' itemprop="offers" itemscope itemtype="http://schema.org/Offer"' : ''; if (edd_item_in_cart($download_id) && !edd_single_price_option_mode($download_id)) { return; } do_action('edd_before_price_options', $download_id); ?> <div class="edd_price_options edd_<?php echo esc_attr($mode); ?> _mode"> <ul> <?php if ($prices) { $checked_key = isset($_GET['price_option']) ? absint($_GET['price_option']) : edd_get_default_variable_price($download_id); foreach ($prices as $key => $price) { echo '<li id="edd_price_option_' . $download_id . '_' . sanitize_key($price['name']) . '"' . $schema . '>'; echo '<label for="' . esc_attr('edd_price_option_' . $download_id . '_' . $key) . '">'; echo '<input type="' . $type . '" ' . checked(apply_filters('edd_price_option_checked', $checked_key, $download_id, $key), $key, false) . ' name="edd_options[price_id][]" id="' . esc_attr('edd_price_option_' . $download_id . '_' . $key) . '" class="' . esc_attr('edd_price_option_' . $download_id) . '" value="' . esc_attr($key) . '" data-price="' . edd_get_price_option_amount($download_id, $key) . '"/> '; echo '<span class="edd_price_option_name" itemprop="description">' . esc_html($price['name']) . '</span><span class="edd_price_option_sep"> – </span><span class="edd_price_option_price" itemprop="price">' . edd_currency_filter(edd_format_amount($price['amount'])) . '</span>'; echo '</label>'; do_action('edd_after_price_option', $key, $price, $download_id); echo '</li>'; } } do_action('edd_after_price_options_list', $download_id, $prices, $type); ?> </ul> </div><!--end .edd_price_options--> <?php do_action('edd_after_price_options', $download_id); }
/** * Generate PDF Reports * * Generates PDF report on sales and earnings for all downloads for the current year. * * @since 1.1.4.0 * @param string $data * @uses edd_pdf * @author Sunny Ratilal */ function edd_generate_pdf($data) { if (!current_user_can('view_shop_reports')) { wp_die(__('You do not have permission to generate PDF sales reports', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403)); } if (!wp_verify_nonce($_GET['_wpnonce'], 'edd_generate_pdf')) { wp_die(__('Nonce verification failed', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403)); } require_once EDD_PLUGIN_DIR . '/includes/libraries/fpdf/fpdf.php'; require_once EDD_PLUGIN_DIR . '/includes/libraries/fpdf/edd_pdf.php'; $daterange = date_i18n(get_option('date_format'), mktime(0, 0, 0, 1, 1, date('Y'))) . ' ' . utf8_decode(__('to', 'easy-digital-downloads')) . ' ' . date_i18n(get_option('date_format')); $pdf = new edd_pdf(); $pdf->AddPage('L', 'A4'); $pdf->SetTitle(utf8_decode(__('Sales and earnings reports for the current year for all products', 'easy-digital-downloads'))); $pdf->SetAuthor(utf8_decode(__('Easy Digital Downloads', 'easy-digital-downloads'))); $pdf->SetCreator(utf8_decode(__('Easy Digital Downloads', 'easy-digital-downloads'))); $pdf->Image(EDD_PLUGIN_URL . 'assets/images/edd-logo-pdf.png', 205, 10); $pdf->SetMargins(8, 8, 8); $pdf->SetX(8); $pdf->SetFont('Helvetica', '', 16); $pdf->SetTextColor(50, 50, 50); $pdf->Cell(0, 3, utf8_decode(__('Sales and earnings reports for the current year for all products', 'easy-digital-downloads')), 0, 2, 'L', false); $pdf->SetFont('Helvetica', '', 13); $pdf->Ln(); $pdf->SetTextColor(150, 150, 150); $pdf->Cell(0, 6, utf8_decode(__('Date Range: ', 'easy-digital-downloads')) . $daterange, 0, 2, 'L', false); $pdf->Ln(); $pdf->SetTextColor(50, 50, 50); $pdf->SetFont('Helvetica', '', 14); $pdf->Cell(0, 10, utf8_decode(__('Table View', 'easy-digital-downloads')), 0, 2, 'L', false); $pdf->SetFont('Helvetica', '', 12); $pdf->SetFillColor(238, 238, 238); $pdf->Cell(70, 6, utf8_decode(__('Product Name', 'easy-digital-downloads')), 1, 0, 'L', true); $pdf->Cell(30, 6, utf8_decode(__('Price', 'easy-digital-downloads')), 1, 0, 'L', true); $category_labels = edd_get_taxonomy_labels('download_category'); $pdf->Cell(50, 6, utf8_decode($category_labels['name']), 1, 0, 'L', true); $pdf->Cell(50, 6, utf8_decode(__('Tags', 'easy-digital-downloads')), 1, 0, 'L', true); $pdf->Cell(45, 6, utf8_decode(__('Number of Sales', 'easy-digital-downloads')), 1, 0, 'L', true); $pdf->Cell(35, 6, utf8_decode(__('Earnings to Date', 'easy-digital-downloads')), 1, 1, 'L', true); $year = date('Y'); $downloads = get_posts(array('post_type' => 'download', 'year' => $year, 'posts_per_page' => -1)); if ($downloads) { $pdf->SetWidths(array(70, 30, 50, 50, 45, 35)); foreach ($downloads as $download) { $pdf->SetFillColor(255, 255, 255); $title = utf8_decode(get_the_title($download->ID)); if (edd_has_variable_prices($download->ID)) { $prices = edd_get_variable_prices($download->ID); $first = $prices[0]['amount']; $last = array_pop($prices); $last = $last['amount']; if ($first < $last) { $min = $first; $max = $last; } else { $min = $last; $max = $first; } $price = html_entity_decode(edd_currency_filter(edd_format_amount($min)) . ' - ' . edd_currency_filter(edd_format_amount($max))); } else { $price = html_entity_decode(edd_currency_filter(edd_get_download_price($download->ID))); } $categories = get_the_term_list($download->ID, 'download_category', '', ', ', ''); $categories = $categories ? strip_tags($categories) : ''; $tags = get_the_term_list($download->ID, 'download_tag', '', ', ', ''); $tags = $tags ? strip_tags($tags) : ''; $sales = edd_get_download_sales_stats($download->ID); $earnings = html_entity_decode(edd_currency_filter(edd_get_download_earnings_stats($download->ID))); if (function_exists('iconv')) { // Ensure characters like euro; are properly converted. See GithuB issue #472 and #1570 $price = iconv('UTF-8', 'windows-1252', utf8_encode($price)); $earnings = iconv('UTF-8', 'windows-1252', utf8_encode($earnings)); } $pdf->Row(array($title, $price, $categories, $tags, $sales, $earnings)); } } else { $pdf->SetWidths(array(280)); $title = utf8_decode(sprintf(__('No %s found.', 'easy-digital-downloads'), edd_get_label_plural())); $pdf->Row(array($title)); } $pdf->Ln(); $pdf->SetTextColor(50, 50, 50); $pdf->SetFont('Helvetica', '', 14); $pdf->Cell(0, 10, utf8_decode(__('Graph View', 'easy-digital-downloads')), 0, 2, 'L', false); $pdf->SetFont('Helvetica', '', 12); $image = html_entity_decode(urldecode(edd_draw_chart_image())); $image = str_replace(' ', '%20', $image); $pdf->SetX(25); $pdf->Image($image . '&file=.png'); $pdf->Ln(7); $pdf->Output(apply_filters('edd_sales_earnings_pdf_export_filename', 'edd-report-' . date_i18n('Y-m-d')) . '.pdf', 'D'); }
/** * Get cart item price name * * @since 1.8 * @param int $item Cart item array * @return string Price name */ function edd_get_cart_item_price_name($item = array()) { $price_id = (int) edd_get_cart_item_price_id($item); $prices = edd_get_variable_prices($item['id']); $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; return apply_filters('edd_get_cart_item_price_name', $name, $item['id'], $price_id, $item); }
/** * Campaign Backers Count * * @since Astoundify Crowdfunding 0.1-alpha * * @return int Campaign Backers Count */ public function backers_count() { $prices = edd_get_variable_prices($this->ID); $count = 0; if (empty($prices)) { return $count; } foreach ($prices as $price) { $count += isset($price['bought']) ? $price['bought'] : 0; } return $count; }
/** * Check for Download Price Variations via AJAX (this function can only be used * in WordPress Admin). This function is used for the Edit Payment screen when downloads * are added to the purchase. When each download is chosen, an AJAX call is fired * to this function which will check if variable prices exist for that download. * If they do, it will output a dropdown of all the variable prices available for * that download. * * @author Sunny Ratilal * @since 1.5 * @return void */ function edd_check_for_download_price_variations() { if (!current_user_can('edit_products')) { die('-1'); } $download_id = intval($_POST['download_id']); $download = get_post($download_id); if ('download' != $download->post_type) { die('-2'); } if (edd_has_variable_prices($download_id)) { $variable_prices = edd_get_variable_prices($download_id); if ($variable_prices) { $ajax_response = '<select class="edd_price_options_select edd-select edd-select" name="edd_price_option">'; if (isset($_POST['all_prices'])) { $ajax_response .= '<option value="">' . __('All Prices', 'easy-digital-downloads') . '</option>'; } foreach ($variable_prices as $key => $price) { $ajax_response .= '<option value="' . esc_attr($key) . '">' . esc_html($price['name']) . '</option>'; } $ajax_response .= '</select>'; echo $ajax_response; } } edd_die(); }
function idedd_payment_vars($paymeta, $payment_id, $download_id, $level, $count, $qty_num) { $vars = array(); $post = get_post($payment_id); if (isset($post)) { $status = strtoupper(substr($post->post_status, 0, 1)); $date = $post->post_date; } else { $status = 'P'; } if (is_array($paymeta['user_info'])) { // strange but seems that after editing, it saves as array and not serialized array $user_info = $paymeta['user_info']; } else { $user_info = unserialize($paymeta['user_info']); } if (isset($user_info['first_name'])) { $first_name = $user_info['first_name']; } else { $first_name = ''; } if (isset($user_info['last_name'])) { $last_name = $user_info['last_name']; } else { $last_name = ''; } if (isset($user_info['email'])) { $email = $user_info['email']; } else { $email = ''; } $cart_details = maybe_unserialize($paymeta['cart_details']); $price_array = edd_get_variable_prices($download_id); $price = $price_array[$level - 1]['amount']; if (!isset($date)) { $date = null; } if (isset($download_id) && $download_id > 0) { $project_id = get_post_meta($download_id, '_edd_project_pairing', true); if (isset($project_id) && $project_id > 0) { $project = new ID_Project($project_id); $the_project = $project->the_project(); $vars = array('id' => null, 'first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'address' => '', 'state' => '', 'city' => '', 'zip' => '', 'country' => '', 'product_id' => $project_id, 'transaction_id' => $payment_id . '-v' . $level . '-' . $count . '-' . $qty_num, 'preapproval_key' => '', 'product_level' => $level, 'prod_price' => $price, 'status' => $status, 'created_at' => $date); } } return isset($vars) ? $vars : array(); }
<?php /** * @package Yoast\YoastCom */ namespace Yoast\YoastCom\Theme; $pricing_option = ''; if (isset($template_args['download_id']) && isset($template_args['price_id'])) { $pricing_options = edd_get_variable_prices($template_args['download_id']); $pricing_option = $pricing_options[$template_args['price_id']]; $pricing_option = $pricing_option['name']; } ?> <?php _e('Option:', 'yoastcom'); ?> <?php echo esc_html($pricing_option);
/** * Render our file row * * @since 1.0 * @return void */ public function edd_render_file_row($key = 0, $args = array(), $post_id) { $defaults = array('name' => null, 'file' => null, 'condition' => null, 'attachment_id' => null, 'git_url' => null, 'git_folder_name' => null, 'git_version' => null); $args = wp_parse_args($args, $defaults); $prices = edd_get_variable_prices($post_id); $variable_pricing = edd_has_variable_prices($post_id); $variable_display = $variable_pricing ? '' : ' style="display:none;"'; $repos = $this->instance->repos->fetch_repos($args); $current_tags = $this->instance->repos->fetch_tags($args['git_url']); if (!empty($args['git_url'])) { $repo = parse_url($args['git_url']); $path = $repo['path']; $repo_slug = explode('/', $path); $repo_slug = $repo_slug[2]; $default_file_name = $repo_slug . '-' . $args['git_version'] . '.zip'; } else { $repo_slug = ''; $current_tags = array(); $default_file_name = ''; } ?> <input type="hidden" name="edd_download_files[<?php echo $key; ?> ][attachment_id]" value="0"> <input type="hidden" id="edd_git_file" name="edd_download_files[<?php echo $key; ?> ][file]" value="<?php echo $args['file']; ?> "> <td style="width: 20%"> <div class="edd_repeatable_upload_field_container"> <select name="edd_download_files[<?php echo $key; ?> ][git_url]" class="git-repo" style="width:100%"> <?php $this->output_repo_options($repos, $args['git_url']); ?> </select> </div> </td> <td> <a href="#" class="edd-git-fetch-repos"><span class="dashicons dashicons-update"></span><span class="spinner" style="margin-left: -1px; float:left; display:none;"></a> </td> <td> <div class="edd_repeatable_upload_field_container git-tag-div"> <select name="edd_download_files[<?php echo $key; ?> ][git_version]" style="min-width:125px;" class="git-tag"> <?php foreach ($current_tags as $tag) { ?> <option value="<?php echo $tag; ?> " <?php selected($tag == $args['git_version']); ?> ><?php echo $tag; ?> </option> <?php } ?> </select> </div> <div class="git-tag-spinner" style="display:none;"> <span class="spinner" style="visibility:visible;display:block;float:left;margin-bottom:2px;margin-left:15px;"></span> </div> </td> <td> <?php if (is_array($args['git_url']) && isset($args['git_url'])) { $tmp = explode('/', $args['git_url']); $git_repo = $tmp[4]; $tag = $args['git_version']; $default_name = $git_repo . '-' . $tag . '.zip'; if ($args['name'] == $default_name) { $name = ''; } else { $name = $args['name']; } } else { $name = ''; } echo EDD()->html->text(array('name' => 'edd_download_files[' . $key . '][name]', 'value' => $name, 'placeholder' => $default_file_name, 'class' => 'edd_repeatable_name_field large-text git-file-name')); ?> </td> <td style="width: 20%"> <div class="edd_repeatable_upload_field_container"> <?php echo EDD()->html->text(array('name' => 'edd_download_files[' . $key . '][git_folder_name]', 'value' => $args['git_folder_name'], 'placeholder' => $repo_slug, 'class' => 'edd_repeatable_upload_field large-text git-folder-name')); ?> </div> </td> <?php if (!empty($args['file'])) { $check_style = 'style="margin-top:3px;"'; $text_style = 'style="display:none;"'; } else { $check_style = ' style="display:none;margin-top:3px;"'; $text_style = ''; } ?> <td> <div class="edd_repeatable_upload_field_container"> <a href="#" class="button-secondary edd-git-update" style="float:left"><span class="git-update-text" <?php echo $text_style; ?> ><?php _e('Fetch', 'edd-git'); ?> </span><span class="dashicons dashicons-yes git-update-check" <?php echo $check_style; ?> ></span><span class="dashicons dashicons-no-alt git-update-none" style="margin-top:3px;display:none;"></span></a> <span class="spinner git-update-spinner" style="float:left;margin-top:5px;display:none;"></span> </div> </td> <td class="pricing"<?php echo $variable_display; ?> width="10%"> <?php $options = array(); if ($prices) { foreach ($prices as $price_key => $price) { $options[$price_key] = $prices[$price_key]['name']; } } echo EDD()->html->select(array('name' => 'edd_download_files[' . $key . '][condition]', 'class' => 'edd_repeatable_condition_field git-condition', 'options' => $options, 'selected' => $args['condition'], 'show_option_none' => false)); ?> </td> <?php do_action('edd_download_file_table_row', $post_id, $key, $args); ?> <td> <a href="#" class="edd_remove_repeatable" data-type="file" style="background: url(<?php echo admin_url('/images/xit.gif'); ?> ) no-repeat;">×</a> </td> <div id="edd-git-admin-modal-backdrop" style="display: none;"></div> <div id="edd-git-admin-modal-wrap" class="wp-core-ui" style="display: none;"> <div id="edd-git-admin-modal" tabindex="-1"> <div id="admin-modal-title"> <span id="edd-git-modal-title"></span> <button type="button" id="edd-git-admin-modal-close" class="modal-close"><span class="screen-reader-text modal-close">Close</span></button> </div> <div id="modal-contents-wrapper" style="padding:20px;"> <div id="edd-git-admin-modal-content" class="admin-modal-inside"> </div> <div class="submitbox" style="display:block;"> </div> </div> </div> </div> <div class="edd-git-fetch-prompt" style="display:none;"> <?php _e('The git file has not been fetched. Would you like to fetch it first?.', 'edd-git'); ?> </div> <div class="edd-git-fetch-prompt-buttons" style="display:none;"> <div id="edd-git-admin-modal-cancel"> <a class="submitdelete deletion modal-close edd-git-save-cancel" href="#"><?php _e('Cancel', 'edd-git'); ?> </a> </div> <div id="edd-git-admin-modal-update"> <a class="button-primary edd-git-fetch-continue" href="#"><?php _e('Fetch and Continue', 'edd-git'); ?> </a> </div> </div> <?php }
/** * Renders an HTML Dropdown of all the Products (Downloads) * * @access public * @since 1.5 * @param array $args Arguments for the dropdown * @return string $output Product dropdown */ public function product_dropdown($args = array()) { $defaults = array('name' => 'products', 'id' => 'products', 'class' => '', 'multiple' => false, 'selected' => 0, 'chosen' => false, 'number' => 30, 'bundles' => true, 'variations' => false, 'placeholder' => sprintf(__('Choose a %s', 'easy-digital-downloads'), edd_get_label_singular()), 'data' => array('search-type' => 'download')); $args = wp_parse_args($args, $defaults); $product_args = array('post_type' => 'download', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => $args['number']); // Maybe disable bundles if (!$args['bundles']) { $product_args['meta_query'] = array('relation' => 'AND', array('key' => '_edd_product_type', 'value' => 'bundle', 'compare' => 'NOT EXISTS')); } $products = get_posts($product_args); $options = array(); $options[0] = ''; if ($products) { foreach ($products as $product) { $options[absint($product->ID)] = esc_html($product->post_title); if ($args['variations'] && edd_has_variable_prices($product->ID)) { $prices = edd_get_variable_prices($product->ID); foreach ($prices as $key => $value) { $name = !empty($value['name']) ? $value['name'] : ''; $index = !empty($value['index']) ? $value['index'] : $key; if ($name && $index) { $options[absint($product->ID) . '_' . $index] = esc_html($product->post_title . ': ' . $name); } } } } } // This ensures that any selected products are included in the drop down if (is_array($args['selected'])) { foreach ($args['selected'] as $item) { if (!array_key_exists($item, $options)) { $parsed_item = edd_parse_product_dropdown_value($item); if ($parsed_item['price_id'] !== false) { $prices = edd_get_variable_prices((int) $parsed_item['download_id']); foreach ($prices as $key => $value) { $name = isset($value['name']) ? $value['name'] : ''; $index = isset($value['index']) ? $value['index'] : $key; if ($name && $index && (int) $parsed_item['price_id'] === (int) $index) { $options[absint($product->ID) . '_' . $index] = esc_html(get_the_title((int) $parsed_item['download_id']) . ': ' . $name); } } } else { $options[$parsed_item['download_id']] = get_the_title($parsed_item['download_id']); } } } } elseif (false !== $args['selected'] && $args['selected'] !== 0) { if (!array_key_exists($args['selected'], $options)) { $parsed_item = edd_parse_product_dropdown_value($args['selected']); if ($parsed_item['price_id'] !== false) { $prices = edd_get_variable_prices((int) $parsed_item['download_id']); foreach ($prices as $key => $value) { $name = isset($value['name']) ? $value['name'] : ''; $index = isset($value['index']) ? $value['index'] : $key; if ($name && $index && (int) $parsed_item['price_id'] === (int) $index) { $options[absint($product->ID) . '_' . $index] = esc_html(get_the_title((int) $parsed_item['download_id']) . ': ' . $name); } } } else { $options[$parsed_item['download_id']] = get_the_title($parsed_item['download_id']); } } } if (!$args['bundles']) { $args['class'] .= ' no-bundles'; } if ($args['variations']) { $args['class'] .= ' variations'; } $output = $this->select(array('name' => $args['name'], 'selected' => $args['selected'], 'id' => $args['id'], 'class' => $args['class'], 'options' => $options, 'chosen' => $args['chosen'], 'multiple' => $args['multiple'], 'placeholder' => $args['placeholder'], 'show_option_all' => false, 'show_option_none' => false, 'data' => $args['data'])); return $output; }
/** * Individual file row. * * Used to output a table row for each file associated with a download. * Can be called directly, or attached to an action. * * @since 1.2.2 * @param string $key Array key * @param array $args Array of all the arguments passed to the function * @param int $post_id Download (Post) ID * @return void */ function edd_render_file_row($key = '', $args = array(), $post_id) { $defaults = array('name' => null, 'file' => null, 'condition' => null, 'attachment_id' => null); $args = wp_parse_args($args, $defaults); $prices = edd_get_variable_prices($post_id); $variable_pricing = edd_has_variable_prices($post_id); $variable_display = $variable_pricing ? '' : ' style="display:none;"'; ?> <!-- Disabled until we can work out a way to solve the issues raised here: https://github.com/easydigitaldownloads/Easy-Digital-Downloads/issues/1066 <td> <span class="edd_draghandle"></span> </td> --> <td> <input type="hidden" name="edd_download_files[<?php echo absint($key); ?> ][attachment_id]" class="edd_repeatable_attachment_id_field" value="<?php echo esc_attr(absint($args['attachment_id'])); ?> "/> <?php echo EDD()->html->text(array('name' => 'edd_download_files[' . $key . '][name]', 'value' => $args['name'], 'placeholder' => __('File Name', 'edd'), 'class' => 'edd_repeatable_name_field large-text')); ?> </td> <td> <div class="edd_repeatable_upload_field_container"> <?php echo EDD()->html->text(array('name' => 'edd_download_files[' . $key . '][file]', 'value' => $args['file'], 'placeholder' => __('Upload or enter the file URL', 'edd'), 'class' => 'edd_repeatable_upload_field edd_upload_field large-text')); ?> <span class="edd_upload_file"> <a href="#" data-uploader-title="<?php _e('Insert File', 'edd'); ?> " data-uploader-button-text="<?php _e('Insert', 'edd'); ?> " class="edd_upload_file_button" onclick="return false;"><?php _e('Upload a File', 'edd'); ?> </a> </span> </div> </td> <td class="pricing"<?php echo $variable_display; ?> > <?php $options = array(); if ($prices) { foreach ($prices as $price_key => $price) { $options[$price_key] = $prices[$price_key]['name']; } } echo EDD()->html->select(array('name' => 'edd_download_files[' . $key . '][condition]', 'class' => 'edd_repeatable_condition_field', 'options' => $options, 'selected' => $args['condition'], 'show_option_none' => false)); ?> </td> <?php do_action('edd_download_file_table_row', $post_id, $key, $args); ?> <td> <a href="#" class="edd_remove_repeatable" data-type="file" style="background: url(<?php echo admin_url('/images/xit.gif'); ?> ) no-repeat;">×</a> </td> <?php }
<?php the_content(); ?> </div> </div> </div> </section> <?php } ?> <!-- Variable pricing --> <?php $prices = edd_get_variable_prices(get_the_id()); ?> <?php if (edd_has_variable_prices(get_the_id())) { ?> <section id="pricing" class="pt pb bg-white"> <div class="container"> <div class="row"> <h2 class="mb text-center">Pricing Options</h2> <?php $i = 0; ?>
/** * save the input values when the submission form is submitted * * @since 2.0 * * @return void */ function edd_fes_simple_shipping_save_custom_fields($post_id) { if (isset($_POST['edd_simple_shipping']) && isset($_POST['edd_simple_shipping']['enabled'])) { $domestic = !empty($_POST['edd_simple_shipping']['domestic']) ? edd_sanitize_amount($_POST['edd_simple_shipping']['domestic']) : 0; $international = !empty($_POST['edd_simple_shipping']['international']) ? edd_sanitize_amount($_POST['edd_simple_shipping']['international']) : 0; update_post_meta($post_id, '_edd_enable_shipping', '1'); update_post_meta($post_id, '_edd_shipping_domestic', $domestic); update_post_meta($post_id, '_edd_shipping_international', $international); $prices = edd_get_variable_prices($post_id); if (!empty($prices)) { foreach ($prices as $price_id => $price) { $prices[$price_id]['shipping'] = '1'; } update_post_meta($post_id, 'edd_variable_prices', $prices); } } else { delete_post_meta($post_id, '_edd_enable_shipping'); } }
/** * Create sample purchase data for your EDD site * * ## OPTIONS * * --number: The number of purchases to create * --status=<status>: The status to create purchases as * --id=<product_id>: A specific product to create purchase data for * --price_id=<price_id>: A price ID of the specified product * * ## EXAMPLES * * wp edd payments create --number=10 --status=completed * wp edd payments create --number=10 --id=103 */ public function payments($args, $assoc_args) { $error = false; // At some point we'll likely add another action for payments if (!isset($args) || count($args) == 0) { $error = __('No action specified, did you mean', 'easy-digital-downloads'); } elseif (isset($args) && !in_array('create', $args)) { $error = __('Invalid action specified, did you mean', 'easy-digital-downloads'); } if ($error) { foreach ($assoc_args as $key => $value) { $query .= ' --' . $key . '=' . $value; } WP_CLI::error(sprintf($error . ' %s?', 'wp edd payments create' . $query)); return; } // Setup some defaults $number = 1; $status = 'complete'; $id = false; $price_id = false; if (count($assoc_args) > 0) { $number = array_key_exists('number', $assoc_args) ? absint($assoc_args['number']) : $number; $id = array_key_exists('id', $assoc_args) ? absint($assoc_args['id']) : $id; $price_id = array_key_exists('price_id', $assoc_args) ? absint($assoc_args['id']) : false; $tax = array_key_exists('tax', $assoc_args) ? floatval($assoc_args['tax']) : 0; $email = array_key_exists('email', $assoc_args) ? sanitize_email($assoc_args['email']) : '*****@*****.**'; $fname = array_key_exists('fname', $assoc_args) ? sanitize_text_field($assoc_args['fname']) : 'Pippin'; $lname = array_key_exists('lname', $assoc_args) ? sanitize_text_field($assoc_args['lname']) : 'Williamson'; // Status requires a bit more validation if (array_key_exists('status', $assoc_args)) { $stati = array('publish', 'complete', 'pending', 'refunded', 'revoked', 'failed', 'abandoned', 'preapproval', 'cancelled'); if (in_array($assoc_args['status'], $stati)) { $status = $assoc_args['status'] == 'complete' ? 'publish' : $assoc_args['status']; } else { WP_CLI::warning(sprintf(__("Invalid status '%s', defaulting to 'complete'", 'easy-digital-downloads'), $assoc_args['status'])); } } } // Build the user info array $user_info = array('id' => 0, 'email' => $email, 'first_name' => $fname, 'last_name' => $lname, 'discount' => 'none'); for ($i = 0; $i < $number; $i++) { $products = array(); $total = 0; // No specified product if (!$id) { $products = get_posts(array('post_type' => 'download', 'orderby' => 'rand', 'order' => 'ASC', 'posts_per_page' => 1)); } else { $product = get_post($id); if ($product->post_type != 'download') { WP_CLI::error(__('Specified ID is not a product', 'easy-digital-downloads')); return; } $products[] = $product; } $cart_details = array(); // Create the purchases foreach ($products as $key => $download) { if (!is_a($download, 'WP_Post')) { continue; } $options = array(); $final_downloads = array(); // Deal with variable pricing if (edd_has_variable_prices($download->ID)) { $prices = edd_get_variable_prices($download->ID); if (false === $price_id || !array_key_exists($price_id, (array) $prices)) { $price_id = rand(0, count($prices) - 1); } $item_price = $prices[$price_id]['amount']; $options['price_id'] = $price_id; } else { $item_price = edd_get_download_price($download->ID); } $item_number = array('id' => $download->ID, 'quantity' => 1, 'options' => $options); $cart_details[$key] = array('name' => $download->post_title, 'id' => $download->ID, 'item_number' => $item_number, 'item_price' => edd_sanitize_amount($item_price), 'subtotal' => edd_sanitize_amount($item_price), 'price' => edd_sanitize_amount($item_price), 'quantity' => 1, 'discount' => 0, 'tax' => $tax); $final_downloads[$key] = $item_number; $total += $item_price; } $purchase_data = array('price' => edd_sanitize_amount($total), 'tax' => 0, 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $email, 'user_info' => $user_info, 'currency' => edd_get_currency(), 'downloads' => $final_downloads, 'cart_details' => $cart_details, 'status' => 'pending'); $payment_id = edd_insert_payment($purchase_data); remove_action('edd_complete_purchase', 'edd_trigger_purchase_receipt', 999); if ($status != 'pending') { edd_update_payment_status($payment_id, $status); } } WP_CLI::success(sprintf(__('Created %s payments', 'easy-digital-downloads'), $number)); return; }
/** * Retrieves most expensive price option of a variable priced download * * @since 1.4.4 * @param int $download_id ID of the download * @return float Amount of the highest price */ function edd_get_highest_price_option($download_id = 0) { if (empty($download_id)) { $download_id = get_the_ID(); } if (!edd_has_variable_prices($download_id)) { return edd_get_download_price($download_id); } $prices = edd_get_variable_prices($download_id); $high = 0.0; if (!empty($prices)) { $max = 0; foreach ($prices as $key => $price) { if (empty($price['amount'])) { continue; } $max = max($max, $price['amount']); if ($price['amount'] == $max) { $max_id = $key; } } $high = $prices[$max_id]['amount']; } return edd_sanitize_amount($high); }
/** * Process Get Products API Request * * @access public * @author Daniel J Griffiths * @since 1.5 * @param int $product Product (Download) ID * @return array $customers Multidimensional array of the products */ public function get_products($product = null) { $products = array(); if ($product == null) { $products['products'] = array(); $product_list = get_posts(array('post_type' => 'download', 'posts_per_page' => $this->per_page(), 'paged' => $this->get_paged())); if ($product_list) { $i = 0; foreach ($product_list as $product_info) { $products['products'][$i]['info']['id'] = $product_info->ID; $products['products'][$i]['info']['slug'] = $product_info->post_name; $products['products'][$i]['info']['title'] = $product_info->post_title; $products['products'][$i]['info']['create_date'] = $product_info->post_date; $products['products'][$i]['info']['modified_date'] = $product_info->post_modified; $products['products'][$i]['info']['status'] = $product_info->post_status; $products['products'][$i]['info']['link'] = html_entity_decode($product_info->guid); $products['products'][$i]['info']['content'] = $product_info->post_content; $products['products'][$i]['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($product_info->ID)); $products['products'][$i]['stats']['total']['sales'] = edd_get_download_sales_stats($product_info->ID); $products['products'][$i]['stats']['total']['earnings'] = edd_get_download_earnings_stats($product_info->ID); $products['products'][$i]['stats']['monthly_average']['sales'] = edd_get_average_monthly_download_sales($product_info->ID); $products['products'][$i]['stats']['monthly_average']['earnings'] = edd_get_average_monthly_download_earnings($product_info->ID); if (edd_has_variable_prices($product_info->ID)) { foreach (edd_get_variable_prices($product_info->ID) as $price) { $products['products'][$i]['pricing'][sanitize_key($price['name'])] = $price['amount']; } } else { $products['products'][$i]['pricing']['amount'] = edd_get_download_price($product_info->ID); } foreach (edd_get_download_files($product_info->ID) as $file) { $products['products'][$i]['files'][] = $file; } $products['products'][$i]['notes'] = edd_get_product_notes($product_info->ID); $i++; } } } else { if (get_post_type($product) == 'download') { $product_info = get_post($product); $products['products'][0]['info']['id'] = $product_info->ID; $products['products'][0]['info']['slug'] = $product_info->post_name; $products['products'][0]['info']['title'] = $product_info->post_title; $products['products'][0]['info']['create_date'] = $product_info->post_date; $products['products'][0]['info']['modified_date'] = $product_info->post_modified; $products['products'][0]['info']['status'] = $product_info->post_status; $products['products'][0]['info']['link'] = html_entity_decode($product_info->guid); $products['products'][0]['info']['content'] = $product_info->post_content; $products['products'][0]['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($product_info->ID)); $products['products'][0]['stats']['total']['sales'] = edd_get_download_sales_stats($product_info->ID); $products['products'][0]['stats']['total']['earnings'] = edd_get_download_earnings_stats($product_info->ID); $products['products'][0]['stats']['monthly_average']['sales'] = edd_get_average_monthly_download_sales($product_info->ID); $products['products'][0]['stats']['monthly_average']['earnings'] = edd_get_average_monthly_download_earnings($product_info->ID); if (edd_has_variable_prices($product_info->ID)) { foreach (edd_get_variable_prices($product_info->ID) as $price) { $products['products'][0]['pricing'][sanitize_key($price['name'])] = $price['amount']; } } else { $products['products'][0]['pricing']['amount'] = edd_get_download_price($product_info->ID); } foreach (edd_get_download_files($product_info->ID) as $file) { $products['products'][0]['files'][] = $file; } $products['products'][0]['notes'] = edd_get_product_notes($product_info->ID); } else { $error['error'] = sprintf(__('Product %s not found!', 'edd'), $product); return $error; } } return $products; }