/** * 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 }
/** * Get Cart Item Template * * @since 1.0 * @param int $cart_key Cart key * @param array $item Cart item * @param bool $ajax AJAX? * @return string Cart item */ function edd_get_cart_item_template($cart_key, $item, $ajax = false) { global $post; $id = is_array($item) ? $item['id'] : $item; $remove_url = edd_remove_item_url($cart_key); $title = get_the_title($id); $options = !empty($item['options']) ? $item['options'] : array(); $quantity = edd_get_cart_item_quantity($id, $options); $price = edd_get_cart_item_price($id, $options); if (!empty($options)) { $title .= edd_has_variable_prices($item['id']) ? ' <span class="edd-cart-item-separator">-</span> ' . edd_get_price_name($id, $item['options']) : edd_get_price_name($id, $item['options']); } ob_start(); edd_get_template_part('widget', 'cart-item'); $item = ob_get_clean(); $item = str_replace('{item_title}', $title, $item); $item = str_replace('{item_amount}', edd_currency_filter(edd_format_amount($price)), $item); $item = str_replace('{cart_item_id}', absint($cart_key), $item); $item = str_replace('{item_id}', absint($id), $item); $item = str_replace('{item_quantity}', absint($quantity), $item); $item = str_replace('{remove_url}', $remove_url, $item); $subtotal = ''; if ($ajax) { $subtotal = edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())); } $item = str_replace('{subtotal}', $subtotal, $item); return apply_filters('edd_cart_item', $item, $id); }
/** * Render Donwload Columns * * Render the custom columns content. * * @access private * @since 1.0 * @return void */ function edd_render_download_columns($column_name, $post_id) { if (get_post_type($post_id) == 'download') { $sales = edd_get_download_sales_stats($post_id); $earnings = edd_get_download_earnings_stats($post_id); $color = get_post_meta($post_id, '_edd_purchase_color', true); $color = $color ? $color : 'blue'; $purchase_text = get_post_meta($post_id, '_edd_purchase_text', true); $purchase_text = $purchase_text && '' !== $purchase_text ? $purchase_text : __('Purchase', 'edd'); switch ($column_name) { case 'download_category': echo get_the_term_list($post_id, 'download_category', '', ', ', ''); break; case 'download_tag': echo get_the_term_list($post_id, 'download_tag', '', ', ', ''); break; case 'price': echo edd_price($post_id, false); if (!edd_has_variable_prices($post_id)) { echo '<input type="hidden" class="downloadprice-' . $post_id . '" value="' . edd_get_download_price($post_id) . '" />'; } break; case 'sales': echo $sales; break; case 'earnings': echo edd_currency_filter($earnings); break; case 'shortcode': echo '[purchase_link id="' . absint($post_id) . '" text="' . esc_html($purchase_text) . '" style="button" color="' . esc_attr($color) . '"]'; break; } } }
/** * Add To Cart * * Adds a download ID to the shopping cart. * Uses edd_get_cart_contents(). * * @access public * @since 1.0 * @param $download_id - INT the ID number of the download to add to the cart * @param $options - array an array of options, such as variable price * @return string - cart key of the new item */ function edd_add_to_cart($download_id, $options = array()) { $cart = edd_get_cart_contents(); if (!edd_item_in_cart($download_id)) { if ('download' != get_post_type($download_id)) { return; } // not a download product do_action('edd_pre_add_to_cart', $download_id, $options); if (edd_has_variable_prices($download_id) && !isset($options['price_id'])) { // forces to the first price ID if none is specified and download has variable prices $options['price_id'] = 0; } $cart_item = apply_filters('edd_add_to_cart_item', array('id' => $download_id, 'options' => $options)); if (is_array($cart)) { $cart[] = $cart_item; } else { $cart = array($cart_item); } $_SESSION['edd_cart'] = $cart; do_action('edd_post_add_to_cart', $download_id, $options); // clear all the checkout errors, if any edd_clear_errors(); return count($cart) - 1; } }
/** * Render Download Columns * * @since 1.0 * @param string $column_name Column name * @param int $post_id Download (Post) ID * @return void */ function edd_render_download_columns($column_name, $post_id) { if (get_post_type($post_id) == 'download') { global $edd_options; $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button'; $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue'; $purchase_text = !empty($edd_options['add_to_cart_text']) ? $edd_options['add_to_cart_text'] : __('Purchase', 'edd'); switch ($column_name) { case 'download_category': echo get_the_term_list($post_id, 'download_category', '', ', ', ''); break; case 'download_tag': echo get_the_term_list($post_id, 'download_tag', '', ', ', ''); break; case 'price': if (edd_has_variable_prices($post_id)) { echo edd_price_range($post_id); } else { echo edd_price($post_id, false); echo '<input type="hidden" class="downloadprice-' . $post_id . '" value="' . edd_get_download_price($post_id) . '" />'; } break; case 'sales': echo edd_get_download_sales_stats($post_id); break; case 'earnings': echo edd_currency_filter(edd_format_amount(edd_get_download_earnings_stats($post_id))); break; case 'shortcode': echo '[purchase_link id="' . absint($post_id) . '" text="' . esc_html($purchase_text) . '" style="' . $style . '" color="' . esc_attr($color) . '"]'; break; } } }
/** * 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(); }
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(); }
/** * Price * * Displays a formatted price for a download. * * @access public * @since 1.0 * @param int $download_id the ID of the download price to show * @param bool whether to echo or return the results * @return void */ function edd_price($download_id, $echo = true) { 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); } $price = apply_filters('edd_download_price', $price, $download_id); $price = '<span class="edd_price" id="edd_price_' . $download_id . '">' . $price . '</span>'; if ($echo) { echo $price; } else { return $price; } }
/** * 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_price_function($atts) { $atts = shortcode_atts(array('limit' => -1, 'id' => ''), $atts, 'download_price'); if ($atts['id'] != '') { $id = $atts['id']; } else { $id = get_the_id(); } if (edd_has_variable_prices($id)) { $get_default_price = edd_get_default_variable_price($id); return edd_price($id, false, $get_default_price); } else { return edd_price($id, false); } }
/** * Change the button text of a free download. Default is "Free - Add to Cart" * * @since 1.0.0 */ function edd_wp_downloads_text_args($args) { $free_download_text = edd_get_option('edd_wp_downloads_button_text', __('Free Download', 'edd-wp-downloads')); $variable_pricing = edd_has_variable_prices($args['download_id']); if ($args['price'] && $args['price'] !== 'no' && !$variable_pricing) { $price = edd_get_download_price($args['download_id']); if (0 == $price) { $wp_downloads_url = get_post_meta($args['download_id'], '_edd_wp_downloads_url', true); if ($wp_downloads_url) { $args['text'] = $free_download_text; } } } return $args; }
/** * edd_rp_generate_stats * * Generates the full relational data array for all downloads * * * @since 1.0 */ function edd_rp_generate_stats() { $defaults = array('number' => 250); // Data is acquired from the most recent 250 purchase logs to protect performance. If you need to increase or decrease this, use the following filter $log_query = apply_filters('edd_rp_log_query_args', $defaults); $edd_payments_query = new EDD_Payments_Query($log_query); $edd_payments = $edd_payments_query->get_payments(); // Determine what users have purchased what products if (!empty($edd_payments)) { foreach ($edd_payments as $payment) { $user_email = strtolower($payment->user_info['email']); $cart_items = $payment->cart_details; if (is_array($cart_items)) { foreach ($cart_items as $item) { $logs_data[md5($user_email)][] = $item['id']; } } } foreach ($logs_data as &$log) { $log = array_unique($log); } // Itterate through each download and find users who have purchased it, then if they have purhcased any other downloads // add those to the count. $downloads = get_posts(array('post_type' => 'download', 'posts_per_page' => '-1', 'fields' => 'ids')); $relation_array = array(); $display_free = edd_get_option('edd_rp_show_free', 1); foreach ($downloads as $download) { $relation_array[$download] = array(); foreach ($logs_data as $log) { if (in_array($download, $log)) { foreach ($log as $item) { if ($display_free && !edd_has_variable_prices($item) && absint(edd_get_download_price($item)) === 0) { continue; } if (!isset($relation_array[$download][$item])) { $relation_array[$download][$item] = 0; } $relation_array[$download][$item]++; } } } // Since the data inherintly includes itself in it's own array, just unset it. unset($relation_array[$download][$download]); arsort($relation_array[$download]); } update_option('_edd_rp_master_array', $relation_array); } }
/** * Render Download Columns * * @since 1.0 * @param string $column_name Column name * @param int $post_id Download (Post) ID * @return void */ function edd_render_download_columns($column_name, $post_id) { if (get_post_type($post_id) == 'download') { global $edd_options; $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button'; $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue'; $color = $color == 'inherit' ? '' : $color; $purchase_text = !empty($edd_options['add_to_cart_text']) ? $edd_options['add_to_cart_text'] : __('Purchase', 'edd'); switch ($column_name) { case 'download_category': echo get_the_term_list($post_id, 'download_category', '', ', ', ''); break; case 'download_tag': echo get_the_term_list($post_id, 'download_tag', '', ', ', ''); break; case 'price': if (edd_has_variable_prices($post_id)) { echo edd_price_range($post_id); } else { echo edd_price($post_id, false); echo '<input type="hidden" class="downloadprice-' . $post_id . '" value="' . edd_get_download_price($post_id) . '" />'; } break; case 'sales': if (current_user_can('view_product_stats', $post_id)) { echo '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-reports&tab=logs&view=sales&download=' . $post_id)) . '">'; echo edd_get_download_sales_stats($post_id); echo '</a>'; } else { echo '-'; } break; case 'earnings': if (current_user_can('view_product_stats', $post_id)) { echo '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-reports&view=downloads&download-id=' . $post_id)) . '">'; echo edd_currency_filter(edd_format_amount(edd_get_download_earnings_stats($post_id))); echo '</a>'; } else { echo '-'; } break; case 'shortcode': echo '[purchase_link id="' . absint($post_id) . '" text="' . esc_html($purchase_text) . '" style="' . $style . '" color="' . esc_attr($color) . '"]'; break; } } }
/** * 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'); } }
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}"; } } }
/** * Add To Wish List * * Adds a download ID to the wish list. Based off edd_add_to_cart() * * @since 1.0 * * @param int $download_id Download IDs to be added to the cart * @param array $options Array of options, such as variable price * * @return string Cart key of the new item */ function edd_wl_add_to_wish_list($download_id, $options = array(), $list_id) { // get current post meta for wish list $list = get_post_meta($list_id, 'edd_wish_list', true); $download = get_post($download_id); if ('download' != $download->post_type) { return; } // Not a download product if (!current_user_can('edit_post', $download->ID) && ($download->post_status == 'draft' || $download->post_status == 'pending')) { return; } // Do not allow draft/pending to be purchased if can't edit. Fixes #1056 if (edd_has_variable_prices($download_id) && !isset($options['price_id'])) { // Forces to the first price ID if none is specified and download has variable prices $options['price_id'] = 0; } $to_add = array(); if (isset($options['quantity'])) { $quantity = absint($options['quantity']); unset($options['quantity']); } else { $quantity = 1; } if (isset($options['price_id']) && is_array($options['price_id'])) { // Process multiple price options at once foreach ($options['price_id'] as $price) { $price_options = array('price_id' => $price); $to_add[] = apply_filters('edd_add_to_wish_list_item', array('id' => $download_id, 'options' => $price_options, 'quantity' => $quantity)); } } else { // Add a single item $to_add[] = apply_filters('edd_add_to_wish_list_item', array('id' => $download_id, 'options' => $options, 'quantity' => $quantity)); } if (is_array($list)) { $list = array_merge($list, $to_add); } else { $list = $to_add; } // store in meta_key. Will either be new array or a merged array update_post_meta($list_id, 'edd_wish_list', $list); do_action('edd_wl_post_add_to_list', $list_id, $download_id, $options); return $list; }
/** * 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; }
/** * Add To Cart * * Adds a download ID to the shopping cart. * * @since 1.0 * * @param int $download_id Download IDs to be added to the cart * @param array $options Array of options, such as variable price * * @return string Cart key of the new item */ function edd_add_to_cart($download_id, $options = array()) { $cart = edd_get_cart_contents(); if (!edd_item_in_cart($download_id, $options)) { $download = get_post($download_id); if ('download' != $download->post_type) { return; } // Not a download product if (!current_user_can('edit_post', $download->ID) && ($download->post_status == 'draft' || $download->post_status == 'pending')) { return; } // Do not allow draft/pending to be purchased if can't edit. Fixes #1056 do_action('edd_pre_add_to_cart', $download_id, $options); if (edd_has_variable_prices($download_id) && !isset($options['price_id'])) { // Forces to the first price ID if none is specified and download has variable prices $options['price_id'] = 0; } $to_add = array(); if (isset($options['price_id']) && is_array($options['price_id'])) { // Process multiple price options at once foreach ($options['price_id'] as $price) { $price_options = array('price_id' => $price); $to_add[] = apply_filters('edd_add_to_cart_item', array('id' => $download_id, 'options' => $price_options)); } } else { // Add a single item $to_add[] = apply_filters('edd_add_to_cart_item', array('id' => $download_id, 'options' => $options)); } if (is_array($cart)) { $cart = array_merge($cart, $to_add); } else { $cart = $to_add; } EDD()->session->set('edd_cart', $cart); do_action('edd_post_add_to_cart', $download_id, $options); // Clear all the checkout errors, if any edd_clear_errors(); return count($cart) - 1; } }
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); }
/** * Render Download Columns * * @since 1.0 * @param string $column_name Column name * @param int $post_id Download (Post) ID * @return void */ function edd_render_download_columns($column_name, $post_id) { if (get_post_type($post_id) == 'download') { switch ($column_name) { case 'download_category': echo get_the_term_list($post_id, 'download_category', '', ', ', ''); break; case 'download_tag': echo get_the_term_list($post_id, 'download_tag', '', ', ', ''); break; case 'price': if (edd_has_variable_prices($post_id)) { echo edd_price_range($post_id); } else { echo edd_price($post_id, false); echo '<input type="hidden" class="downloadprice-' . $post_id . '" value="' . edd_get_download_price($post_id) . '" />'; } break; case 'sales': if (current_user_can('view_product_stats', $post_id)) { echo '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-reports&tab=logs&view=sales&download=' . $post_id)) . '">'; echo edd_get_download_sales_stats($post_id); echo '</a>'; } else { echo '-'; } break; case 'earnings': if (current_user_can('view_product_stats', $post_id)) { echo '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-reports&view=downloads&download-id=' . $post_id)) . '">'; echo edd_currency_filter(edd_format_amount(edd_get_download_earnings_stats($post_id))); echo '</a>'; } else { echo '-'; } break; } } }
/** * 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; }
/** * This function renders most of the columns in the list table. * * @access public * @since 1.4 * * @param array $item Contains all the data of the log item * @param string $column_name The name of the column * * @return string Column Name */ public function column_default($item, $column_name) { $return = ''; $currency = $item['currency']; switch ($column_name) { case 'download': $download_id = $item[$column_name]; $download = new EDD_Download($download_id); $title = $download->post_title; if (edd_has_variable_prices($download->ID)) { $price_id = $item['price_id']; if (!is_null($price_id) && !empty($download->prices[$price_id])) { $title .= ' — ' . $download->prices[$price_id]['name']; } } $return = '<a href="' . add_query_arg('download', $item[$column_name]) . '" >' . $title . '</a>'; break; case 'user_id': $user = !empty($item['user_id']) ? $item['user_id'] : edd_get_payment_user_email($item['payment_id']); $return = '<a href="' . admin_url('edit.php?post_type=download&page=edd-payment-history&user='******'">' . $item['user_name'] . '</a>'; break; case 'item_price': $return = edd_currency_filter(edd_format_amount($item['item_price']), $currency); break; case 'amount': $return = edd_currency_filter(edd_format_amount($item['amount'] / $item['quantity']), $currency); break; case 'payment_id': $return = '<a href="' . admin_url('edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $item['payment_id']) . '">' . edd_get_payment_number($item['payment_id']) . '</a>'; break; default: $return = $item[$column_name]; break; } return $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); }
/** * Get Downloads Earning Points * * Handles to return earning points for download * * @package Easy Digital Downloads - Points and Rewards * @since 1.0.0 **/ public function edd_points_get_earning_points($downloadid, $priceoptions = array(), $checkout = false) { //if this function called from checkout page then use third parameter to TRUE global $edd_options; $earningpointsbyuser = 0; //check if price is for checkout page if (!empty($checkout)) { //if checkout page $edd_price = edd_get_cart_item_price($downloadid, $priceoptions); } else { //if not is checkout page if (edd_has_variable_prices($downloadid)) { //check product price is varible pricing enable or not //$prices = edd_get_variable_prices( $downloadid ); //$edd_price = edd_sanitize_amount( $prices[0]['amount'] ); $edd_price[0] = edd_get_lowest_price_option($downloadid); $edd_price[1] = edd_get_highest_price_option($downloadid); } else { //get download price $edd_price = edd_get_download_price($downloadid); } //end else } //end else //get download points for download level from meta box $downloadearnpoints = $this->edd_points_get_download_earn_points($downloadid); if (is_numeric($downloadearnpoints)) { return $downloadearnpoints; } //check if points of download are set in category level $downloadearnpoints = $this->edd_points_get_category_earn_points($downloadid); if (is_numeric($downloadearnpoints)) { return $downloadearnpoints; } if (is_array($edd_price)) { // if product is variable then edd_price contains array of lowest and highest price $earning_points_by_user = array(); foreach ($edd_price as $key => $data) { $earning_points_by_user[$key] = $this->edd_points_calculate_earn_points_from_price($data); } return $earning_points_by_user; } else { // if product is simple product //calculate the earn points from price $earningpointsbyuser = $this->edd_points_calculate_earn_points_from_price($edd_price); } // get download points based on global setting return $earningpointsbyuser; }
/** * Get cart item title * * @since 2.4.3 * @param int $item Cart item array * @return string item title */ function edd_get_cart_item_name($item = array()) { $item_title = get_the_title($item['id']); if (empty($item_title)) { $item_title = $item['id']; } if (edd_has_variable_prices($item['id']) && false !== edd_get_cart_item_price_id($item)) { $item_title .= ' - ' . edd_get_cart_item_price_name($item); } return apply_filters('edd_get_cart_item_name', $item_title, $item['id'], $item); }
/** * Determine if a product has snipping enabled * * @since 1.0 * * @access private * @return bool */ private function item_has_shipping($item_id = 0, $price_id = 0) { $enabled = get_post_meta($item_id, '_edd_enable_shipping', true); $variable_pricing = edd_has_variable_prices($item_id); if ($variable_pricing && !$this->price_has_shipping($item_id, $price_id)) { $enabled = false; } return (bool) apply_filters('edd_simple_shipping_item_has_shipping', $enabled, $item_id); }
public function product_list_price($product_id) { if (edd_has_variable_prices($product_id)) { $price = edd_price_range($product_id); } else { $price = edd_price($product_id); } $price = apply_filters('fes_product_list_price', $price, $product_id); return $price; }
<a href="<?php echo esc_url(reset($preview)); ?> " class="item-download pull-right"> <i class="icon-arrow-down text-white"></i> </a> <?php } ?> <?php if (show_purchase($post->ID)) { ?> <div class="inline"> <?php $text = ''; if (edd_has_variable_prices($post->ID)) { $text = edd_price_range($post->ID); } echo edd_get_purchase_link(array('download_id' => $post->ID, 'style' => 'btn btn-xs ' . get_theme_mod('btn-bg-color'), 'text' => $text)); ?> </div> <?php } ?> </div> </div> <a href="<?php the_permalink(); ?> " data-pjax title="<?php
" data-download-id="<?php echo esc_attr($item['id']); ?> "> <?php do_action('edd_checkout_table_body_first', $item); ?> <td class="edd_cart_item_name"> <?php if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) { echo '<div class="edd_cart_item_image">'; echo get_the_post_thumbnail($item['id'], apply_filters('edd_checkout_image_size', array(25, 25))); echo '</div>'; } $item_title = get_the_title($item['id']); if (!empty($item['options']) && edd_has_variable_prices($item['id'])) { $item_title .= ' - ' . edd_get_cart_item_price_name($item); } echo '<span class="edd_checkout_cart_item_title">' . esc_html($item_title) . '</span>'; ?> </td> <td class="edd_cart_item_price"><?php echo edd_cart_item_price($item['id'], $item['options']); ?> </td> <td class="edd_cart_actions form-inline"> <?php if (edd_item_quantities_enabled()) { ?> <input type="number" min="1" step="1" name="edd-cart-download-<?php echo $key;