/**
 * 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;
    }
}
/**
 * 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;
}
/**
 * Get Cart Item Template
 *
 * @access      public
 * @since       1.0
 * @return      string
*/
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, $post, $ajax);
    $title = get_the_title($id);
    $options = !empty($item['options']) ? $item['options'] : array();
    $price = edd_get_cart_item_price($id, $options);
    if (edd_use_taxes() && edd_taxes_on_prices()) {
        $price += edd_calculate_tax($price);
    }
    if (!empty($options)) {
        $title .= ' <span class="edd-cart-item-separator">-</span> ' . edd_get_price_name($id, $item['options']);
    }
    $remove = '<a href="' . esc_url($remove_url) . '" data-cart-item="' . absint($cart_key) . '" data-download-id="' . absint($id) . '" data-action="edd_remove_from_cart" class="edd-remove-from-cart">' . __('remove', 'edd') . '</a>';
    $item = '<li class="edd-cart-item"><span class="edd-cart-item-title">' . $title . '</span>&nbsp;';
    $item .= '<span class="edd-cart-item-separator">-</span>&nbsp;' . edd_currency_filter(edd_format_amount($price)) . '&nbsp;';
    $item .= '<span class="edd-cart-item-separator">-</span> ' . $remove . '</li>';
    return apply_filters('edd_cart_item', $item, $id);
}
Example #4
0
/**
 * Contribute now list options
 * @return void
**/
function wpo_campaign_contribute_options_custom($prices, $type, $download_id)
{
    $campaign = atcf_get_campaign($download_id);
    $uid = wpo_makeid();
    ?>
	<div class="edd_price_options <?php 
    echo $campaign->is_active() ? 'active' : 'expired';
    ?>
" <?php 
    echo $campaign->is_donations_only() ? 'style="display: none"' : null;
    ?>
>
		<ul>
			<?php 
    foreach ($prices as $key => $price) {
        ?>
				<?php 
        $amount = $price['amount'];
        $limit = isset($price['limit']) ? $price['limit'] : '';
        $bought = isset($price['bought']) ? $price['bought'] : 0;
        $allgone = false;
        if ($bought == absint($limit) && '' != $limit) {
            $allgone = true;
        }
        if (edd_use_taxes() && edd_taxes_on_prices()) {
            $amount += edd_calculate_tax($amount);
        }
        ?>
				<li class="atcf-price-option pledge-level <?php 
        echo $allgone ? 'inactive' : null;
        ?>
"  data-pri="<?php 
        echo edd_sanitize_amount($amount);
        ?>
"  data-price="<?php 
        echo edd_sanitize_amount($amount);
        ?>
-<?php 
        echo esc_attr($key);
        ?>
">
					<div class="clear">
						<h3><label><!-- <label for="<?php 
        echo esc_attr('edd_price_option_' . $download_id . '_' . $key);
        ?>
"> -->
							<?php 
        if ($campaign->is_active()) {
            if (!$allgone) {
                printf('<input type="radio" name="edd_options[price_id][]" id="%1$s" class="%2$s edd_price_options_input" value="%3$s"/>', esc_attr('edd_price_option_' . $download_id . '_' . $key . '_' . $uid), esc_attr('edd_price_option_' . $download_id), esc_attr($key));
            }
        }
        ?>
  
							<?php 
        echo edd_currency_filter(edd_format_amount($amount));
        ?>
						</label></h3>
						
						<div class="backers hidden">
							<div class="backer-count">
								<i class="icon-user"></i> <?php 
        printf(_n('1 Backer', '%1$s Backers', $bought, 'atcf'), $bought);
        ?>
							</div>
							<?php 
        if ('' != $limit && !$allgone) {
            ?>
								<small class="limit"><?php 
            printf(__('Limit of %d &mdash; %d remaining', 'atcf'), $limit, $limit - $bought);
            ?>
</small>
							<?php 
        } elseif ($allgone) {
            ?>
								<small class="gone"><?php 
            _e('All gone!', 'atcf');
            ?>
</small>
							<?php 
        }
        ?>
						</div>

					</div>
					<?php 
        //echo wpautop( wp_kses_data( $price[ 'name' ] ) );
        ?>
				</li>

			<?php 
    }
    ?>
			<li class="price-custom">
				<div class="campaign-price-input">
					<div class="price-wrapper"><span class="title"><?php 
    _e('Amount: ', TEXTDOMAIN);
    ?>
</span><input type="text" name="atcf_custom_price" value="" /></div>
				</div>	
			</li>

		</ul>
	</div><!--end .edd_price_options-->
<?php 
}
/**
 * Get Cart Item Price
 *
 * Gets the quanity for an item in the cart.
 *
 * @access      public
 * @since       1.0
 * @param       $item INT the download (cart item) ID number
 * @param       $options - array optional parameters, used for defining variable prices
 * @return      string - the fully formatted price
*/
function edd_cart_item_price($item_id = 0, $options = array())
{
    $price = edd_get_cart_item_price($item_id, $options);
    if (edd_use_taxes() && edd_taxes_on_prices()) {
        $price += edd_calculate_tax($price);
    }
    return esc_html(edd_currency_filter(edd_format_amount($price)));
}
/**
 * Variable price output
 *
 * To override this output, remove this action, then add
 * your own via a theme, child theme, or plugin.
 *
 * @access      public
 * @since       1.2.3
 * @return      void
 */
function edd_purchase_variable_pricing($download_id)
{
    $variable_pricing = edd_has_variable_prices($download_id);
    if (!$variable_pricing) {
        return;
    }
    $prices = edd_get_variable_prices($download_id);
    do_action('edd_before_price_options', $download_id);
    ?>
	<div class="edd_price_options">
		<ul>
			<?php 
    if ($prices) {
        foreach ($prices as $key => $price) {
            $amount = $price['amount'];
            if (edd_use_taxes() && edd_taxes_on_prices()) {
                $amount += edd_calculate_tax($price['amount']);
            }
            printf('<li><label for="%2$s"><input type="radio" %1$s name="edd_options[price_id]" id="%2$s" class="%3$s" value="%4$s"/> %5$s</label></li>', checked(0, $key, false), 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($amount))));
        }
    }
    ?>
		</ul>
	</div><!--end .edd_price_options-->
<?php 
    add_action('edd_after_price_options', $download_id);
}