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(); }
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); } }
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}"; } } }
/** * Individual Price Row * * Used to output a table row for each price associated with a download. * Can be called directly, or attached to an action. * * @since 1.2.2 * * @param $key * @param array $args * @param $post_id */ function edd_render_price_row($key, $args = array(), $post_id, $index) { $defaults = array('name' => null, 'amount' => null); $args = wp_parse_args($args, $defaults); $default_price_id = edd_get_default_variable_price($post_id); $currency_position = edd_get_option('currency_position', 'before'); ?> <td> <span class="edd_draghandle"></span> <input type="hidden" name="edd_variable_prices[<?php echo $key; ?> ][index]" class="edd_repeatable_index" value="<?php echo $index; ?> "/> </td> <td> <?php echo EDD()->html->text(array('name' => 'edd_variable_prices[' . $key . '][name]', 'value' => esc_attr($args['name']), 'placeholder' => __('Option Name', 'edd'), 'class' => 'edd_variable_prices_name large-text')); ?> </td> <td> <?php $price_args = array('name' => 'edd_variable_prices[' . $key . '][amount]', 'value' => $args['amount'], 'placeholder' => '9.99', 'class' => 'edd-price-field'); ?> <?php if ($currency_position == 'before') { ?> <span><?php echo edd_currency_filter(''); ?> </span> <?php echo EDD()->html->text($price_args); ?> <?php } else { ?> <?php echo EDD()->html->text($price_args); ?> <?php echo edd_currency_filter(''); ?> <?php } ?> </td> <td class="edd_repeatable_default_wrapper"> <input type="radio" <?php checked($default_price_id, $key, true); ?> class="edd_repeatable_default_input" name="_edd_default_price_id" value="<?php echo $key; ?> " /> <td> <span class="edd_price_id"><?php echo $key; ?> </span> </td> <?php do_action('edd_download_price_table_row', $post_id, $key, $args); ?> <td> <a href="#" class="edd_remove_repeatable" data-type="price" style="background: url(<?php echo admin_url('/images/xit.gif'); ?> ) no-repeat;">×</a> </td> <?php }
/** * 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); }
/** * 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()) { global $edd_displayed_form_ids; // If we've already generated a form ID for this download ID, append -# $form_id = ''; if ($edd_displayed_form_ids[$download_id] > 1) { $form_id .= '-' . $edd_displayed_form_ids[$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); // 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"' : ''; // Filter the class names for the edd_price_options div $css_classes_array = apply_filters('edd_price_options_classes', array('edd_price_options', 'edd_' . esc_attr($mode) . '_mode'), $download_id); // Sanitize those class names and form them into a string $css_classes_string = implode(array_map('sanitize_html_class', $css_classes_array), ' '); 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="<?php echo esc_attr(rtrim($css_classes_string)); ?> "> <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']) . $form_id . '"' . $schema . '>'; echo '<label for="' . esc_attr('edd_price_option_' . $download_id . '_' . $key . $form_id) . '">'; 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 . $form_id) . '" class="' . esc_attr('edd_price_option_' . $download_id) . '" value="' . esc_attr($key) . '" data-price="' . edd_get_price_option_amount($download_id, $key) . '"/> '; $item_prop = edd_add_schema_microdata() ? ' itemprop="description"' : ''; echo '<span class="edd_price_option_name"' . $item_prop . '>' . esc_html($price['name']) . '</span><span class="edd_price_option_sep"> – </span><span class="edd_price_option_price">' . edd_currency_filter(edd_format_amount($price['amount'])) . '</span>'; if (edd_add_schema_microdata()) { echo '<meta itemprop="price" content="' . esc_attr($price['amount']) . '" />'; echo '<meta itemprop="priceCurrency" content="' . esc_attr(edd_get_currency()) . '" />'; } 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); }
/** * Displays a formatted price for a download * * @since 1.0 * @param int $download_id ID of the download price to show * @param bool $echo Whether to echo or return the results * @param int $price_id Optional price id for variable pricing * @return void */ function edd_price($download_id = 0, $echo = true, $price_id = false) { if (empty($download_id)) { $download_id = get_the_ID(); } if (edd_has_variable_prices($download_id)) { $prices = edd_get_variable_prices($download_id); if (false !== $price_id && isset($prices[$price_id])) { $price = edd_get_price_option_amount($download_id, $price_id); } elseif ($default = edd_get_default_variable_price($download_id)) { $price = edd_get_price_option_amount($download_id, $default); } else { $price = edd_get_lowest_price_option($download_id); } $price = edd_sanitize_amount($price); } else { $price = edd_get_download_price($download_id); } $price = apply_filters('edd_download_price', edd_sanitize_amount($price), $download_id, $price_id); $formatted_price = '<span class="edd_price" id="edd_price_' . $download_id . '">' . $price . '</span>'; $formatted_price = apply_filters('edd_download_price_after_html', $formatted_price, $download_id, $price, $price_id); if ($echo) { echo $formatted_price; } else { return $formatted_price; } }
/** * Display variable price. * * Display the variable price with a strikethrough in the list. * NOTE! This function replaces an entire EDD function! * * @since 1.0.0 * * @param int $download_id ID of the download to get the labels for. * @param array $args Array of arguments related to the download price. */ public function edd_purchase_variable_pricing($download_id = 0, $args = array()) { global $edd_options; $variable_pricing = edd_has_variable_prices($download_id); $prices = apply_filters('edd_purchase_variable_prices', edd_get_variable_prices($download_id), $download_id); if (!$variable_pricing || false !== $args['price_id'] && isset($prices[$args['price_id']])) { return; } if (edd_item_in_cart($download_id) && !edd_single_price_option_mode($download_id)) { return; } $type = edd_single_price_option_mode($download_id) ? 'checkbox' : 'radio'; $mode = edd_single_price_option_mode($download_id) ? 'multi' : 'single'; 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) { ?> <li id="edd_price_option_<?php echo $download_id . '_' . sanitize_key($price['name']); ?> " itemprop="offers" itemscope itemtype="http://schema.org/Offer"> <label for="<?php echo esc_attr('edd_price_option_' . $download_id . '_' . $key); ?> "> <input type="<?php echo $type; ?> " <?php checked(apply_filters('edd_price_option_checked', $checked_key, $download_id, $key), $key); ?> name="edd_options[price_id][]" id="<?php echo esc_attr('edd_price_option_' . $download_id . '_' . $key); ?> " class="<?php echo esc_attr('edd_price_option_' . $download_id); ?> " value="<?php echo esc_attr($key); ?> "/> <span class='edd_price_option_wrap'> <span class="edd_price_option_name" itemprop="description"><?php echo esc_html($price['name']); ?> </span> <span class="edd_price_option_sep">–</span> <?php if (isset($price['sale_price']) && !empty($price['sale_price']) && isset($price['regular_amount'])) { ?> <span class="edd_price_option_price regular_price" itemprop="price"><del><?php echo edd_currency_filter(edd_format_amount($price['regular_amount'])); ?> </del></span> <?php } ?> <span class="edd_price_option_price" itemprop="price"><?php echo edd_currency_filter(edd_format_amount($price['amount'])); ?> </span> </span> </label><?php do_action('edd_after_price_option', $key, $price, $download_id); ?> </li><?php } } 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); }