/**
 * Get cart item tax
 *
 * @since 1.9
 * @param array $download_id Download ID
 * @param array $options Cart item options
 * @param float $subtotal Cart item subtotal
 * @return float Tax amount
 */
function edd_get_cart_item_tax($download_id = 0, $options = array(), $subtotal = '')
{
    $tax = 0;
    if (!edd_download_is_tax_exclusive($download_id)) {
        $country = !empty($_POST['billing_country']) ? $_POST['billing_country'] : false;
        $state = !empty($_POST['card_state']) ? $_POST['card_state'] : false;
        $tax = edd_calculate_tax($subtotal, $country, $state);
    }
    return apply_filters('edd_get_cart_item_tax', $tax, $download_id, $options, $subtotal);
}
Пример #2
0
/**
 * Product tax settings
 *
 * Outputs the option to mark whether a product is exclusive of tax
 *
 * @since 1.9
 * @param int $post_id Download (Post) ID
 * @return void
 */
function edd_render_dowwn_tax_options($post_id = 0)
{
    if (!current_user_can('manage_shop_settings') || !edd_use_taxes()) {
        return;
    }
    $exclusive = edd_download_is_tax_exclusive($post_id);
    ?>
	<p><strong><?php 
    _e('Ignore Tax:', 'edd');
    ?>
</strong></p>
	<label for="_edd_download_tax_exclusive">
		<?php 
    echo EDD()->html->checkbox(array('name' => '_edd_download_tax_exclusive', 'current' => $exclusive));
    ?>
		<?php 
    _e('Mark this product as exclusive of tax', 'edd');
    ?>
	</label>
<?php 
}
 /**
  * Checkout sale price.
  *
  * Display the sale price, and the regular price with a strike at the checkout.
  * This requires a hook added in EDD 2.3.0
  *
  * @since 1.0.0, EDD 2.4.0
  *
  * @param	double 	$price 			Regular price of the product.
  * @param	int		$download_id	ID of the download we're changing the price for.
  * @return	double					The new price, if the product is in sale this will be the sale price.
  */
 public function checkout_maybe_display_sale_price($label, $item_id, $options)
 {
     global $edd_options;
     $download = new EDD_Download($item_id);
     $regular_price = get_post_meta($item_id, 'edd_price', true);
     $price = edd_get_cart_item_price($item_id, $options);
     // Get sale price if it exists
     if ($download->has_variable_prices()) {
         $prices = $download->get_prices();
         $regular_price = isset($prices[$options['price_id']]['regular_amount']) ? $prices[$options['price_id']]['regular_amount'] : $regular_price;
         $sale_price = $prices[$options['price_id']]['sale_price'];
     } else {
         $sale_price = get_post_meta($item_id, 'edd_sale_price', true);
     }
     // Bail if no sale price is set
     if (empty($sale_price)) {
         return $label;
     }
     $label = '';
     $price_id = isset($options['price_id']) ? $options['price_id'] : false;
     if (!edd_is_free_download($item_id, $price_id) && !edd_download_is_tax_exclusive($item_id)) {
         if (edd_prices_show_tax_on_checkout() && !edd_prices_include_tax()) {
             $regular_price += edd_get_cart_item_tax($item_id, $options, $regular_price);
             $price += edd_get_cart_item_tax($item_id, $options, $price);
         }
         if (!edd_prices_show_tax_on_checkout() && edd_prices_include_tax()) {
             $regular_price -= edd_get_cart_item_tax($item_id, $options, $regular_price);
             $price -= edd_get_cart_item_tax($item_id, $options, $price);
         }
         if (edd_display_tax_rate()) {
             $label = '&nbsp;&ndash;&nbsp;';
             if (edd_prices_show_tax_on_checkout()) {
                 $label .= sprintf(__('includes %s tax', 'edd'), edd_get_formatted_tax_rate());
             } else {
                 $label .= sprintf(__('excludes %s tax', 'edd'), edd_get_formatted_tax_rate());
             }
             $label = apply_filters('edd_cart_item_tax_description', $label, $item_id, $options);
         }
     }
     $regular_price = '<del>' . edd_currency_filter(edd_format_amount($regular_price)) . '</del>';
     $price = edd_currency_filter(edd_format_amount($price));
     return $regular_price . ' ' . $price . $label;
 }
/**
 * Get Purchase Link
 *
 * Builds a Purchase link for a specified download based on arguments passed.
 * This function is used all over EDD to generate the Purchase or Add to Cart
 * buttons. If no arguments are passed, the function uses the defaults that have
 * been set by the plugin. The Purchase link is built for simple and variable
 * pricing and filters are available throughout the function to override
 * certain elements of the function.
 *
 * $download_id = null, $link_text = null, $style = null, $color = null, $class = null
 *
 * @since 1.0
 * @param array $args Arguments for display
 * @return string $purchase_form
 */
function edd_get_purchase_link($args = array())
{
    global $post, $edd_displayed_form_ids;
    $purchase_page = edd_get_option('purchase_page', false);
    if (!$purchase_page || $purchase_page == 0) {
        edd_set_error('set_checkout', sprintf(__('No checkout page has been configured. Visit <a href="%s">Settings</a> to set one.', 'easy-digital-downloads'), admin_url('edit.php?post_type=download&page=edd-settings')));
        edd_print_errors();
        return false;
    }
    $post_id = is_object($post) ? $post->ID : 0;
    $button_behavior = edd_get_download_button_behavior($post_id);
    $defaults = apply_filters('edd_purchase_link_defaults', array('download_id' => $post_id, 'price' => (bool) true, 'price_id' => isset($args['price_id']) ? $args['price_id'] : false, 'direct' => $button_behavior == 'direct' ? true : false, 'text' => $button_behavior == 'direct' ? edd_get_option('buy_now_text', __('Buy Now', 'easy-digital-downloads')) : edd_get_option('add_to_cart_text', __('Purchase', 'easy-digital-downloads')), 'style' => edd_get_option('button_style', 'button'), 'color' => edd_get_option('checkout_color', 'blue'), 'class' => 'edd-submit'));
    $args = wp_parse_args($args, $defaults);
    // Override the straight_to_gateway if the shop doesn't support it
    if (!edd_shop_supports_buy_now()) {
        $args['direct'] = false;
    }
    $download = new EDD_Download($args['download_id']);
    if (empty($download->ID)) {
        return false;
    }
    if ('publish' !== $download->post_status && !current_user_can('edit_product', $download->ID)) {
        return false;
        // Product not published or user doesn't have permission to view drafts
    }
    // Override color if color == inherit
    $args['color'] = $args['color'] == 'inherit' ? '' : $args['color'];
    $options = array();
    $variable_pricing = $download->has_variable_prices();
    $data_variable = $variable_pricing ? ' data-variable-price="yes"' : 'data-variable-price="no"';
    $type = $download->is_single_price_mode() ? 'data-price-mode=multi' : 'data-price-mode=single';
    $show_price = $args['price'] && $args['price'] !== 'no';
    $data_price_value = 0;
    $price = false;
    if ($variable_pricing && false !== $args['price_id']) {
        $price_id = $args['price_id'];
        $prices = $download->prices;
        $options['price_id'] = $args['price_id'];
        $found_price = isset($prices[$price_id]) ? $prices[$price_id]['amount'] : false;
        $data_price_value = $found_price;
        if ($show_price) {
            $price = $found_price;
        }
    } elseif (!$variable_pricing) {
        $data_price_value = $download->price;
        if ($show_price) {
            $price = $download->price;
        }
    }
    $args['display_price'] = $data_price_value;
    $data_price = 'data-price="' . $data_price_value . '"';
    $button_text = !empty($args['text']) ? '&nbsp;&ndash;&nbsp;' . $args['text'] : '';
    if (false !== $price) {
        if (0 == $price) {
            $args['text'] = __('Free', 'easy-digital-downloads') . $button_text;
        } else {
            $args['text'] = edd_currency_filter(edd_format_amount($price)) . $button_text;
        }
    }
    if (edd_item_in_cart($download->ID, $options) && (!$variable_pricing || !$download->is_single_price_mode())) {
        $button_display = 'style="display:none;"';
        $checkout_display = '';
    } else {
        $button_display = '';
        $checkout_display = 'style="display:none;"';
    }
    // Collect any form IDs we've displayed already so we can avoid duplicate IDs
    if (isset($edd_displayed_form_ids[$download->ID])) {
        $edd_displayed_form_ids[$download->ID]++;
    } else {
        $edd_displayed_form_ids[$download->ID] = 1;
    }
    $form_id = !empty($args['form_id']) ? $args['form_id'] : 'edd_purchase_' . $download->ID;
    // If we've already generated a form ID for this download ID, append -#
    if ($edd_displayed_form_ids[$download->ID] > 1) {
        $form_id .= '-' . $edd_displayed_form_ids[$download->ID];
    }
    $args = apply_filters('edd_purchase_link_args', $args);
    ob_start();
    ?>
	<form id="<?php 
    echo $form_id;
    ?>
" class="edd_download_purchase_form edd_purchase_<?php 
    echo absint($download->ID);
    ?>
" method="post">

		<?php 
    do_action('edd_purchase_link_top', $download->ID, $args);
    ?>

		<div class="edd_purchase_submit_wrapper">
			<?php 
    $class = implode(' ', array($args['style'], $args['color'], trim($args['class'])));
    if (!edd_is_ajax_disabled()) {
        echo '<a href="#" class="edd-add-to-cart ' . esc_attr($class) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($download->ID) . '" ' . $data_variable . ' ' . $type . ' ' . $data_price . ' ' . $button_display . '><span class="edd-add-to-cart-label">' . $args['text'] . '</span> <span class="edd-loading"><i class="edd-icon-spinner edd-icon-spin"></i></span></a>';
    }
    echo '<input type="submit" class="edd-add-to-cart edd-no-js ' . esc_attr($class) . '" name="edd_purchase_download" value="' . esc_attr($args['text']) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($download->ID) . '" ' . $data_variable . ' ' . $type . ' ' . $button_display . '/>';
    echo '<a href="' . esc_url(edd_get_checkout_uri()) . '" class="edd_go_to_checkout ' . esc_attr($class) . '" ' . $checkout_display . '>' . __('Checkout', 'easy-digital-downloads') . '</a>';
    ?>

			<?php 
    if (!edd_is_ajax_disabled()) {
        ?>
				<span class="edd-cart-ajax-alert" aria-live="assertive">
					<span class="edd-cart-added-alert" style="display: none;">
						<?php 
        echo '<i class="edd-icon-ok" aria-hidden="true"></i> ' . __('Added to cart', 'easy-digital-downloads');
        ?>
					</span>
				</span>
			<?php 
    }
    ?>
			<?php 
    if (!$download->is_free($args['price_id']) && !edd_download_is_tax_exclusive($download->ID)) {
        ?>
				<?php 
        if (edd_display_tax_rate() && edd_prices_include_tax()) {
            echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Includes %1$s&#37; tax', 'easy-digital-downloads'), edd_get_tax_rate() * 100) . '</span>';
        } elseif (edd_display_tax_rate() && !edd_prices_include_tax()) {
            echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Excluding %1$s&#37; tax', 'easy-digital-downloads'), edd_get_tax_rate() * 100) . '</span>';
        }
        ?>
			<?php 
    }
    ?>
		</div><!--end .edd_purchase_submit_wrapper-->

		<input type="hidden" name="download_id" value="<?php 
    echo esc_attr($download->ID);
    ?>
">
		<?php 
    if ($variable_pricing && isset($price_id) && isset($prices[$price_id])) {
        ?>
			<input type="hidden" name="edd_options[price_id][]" id="edd_price_option_<?php 
        echo $download->ID;
        ?>
_1" class="edd_price_option_<?php 
        echo $download->ID;
        ?>
" value="<?php 
        echo $price_id;
        ?>
">
		<?php 
    }
    ?>
		<?php 
    if (!empty($args['direct']) && !$download->is_free($args['price_id'])) {
        ?>
			<input type="hidden" name="edd_action" class="edd_action_input" value="straight_to_gateway">
		<?php 
    } else {
        ?>
			<input type="hidden" name="edd_action" class="edd_action_input" value="add_to_cart">
		<?php 
    }
    ?>

		<?php 
    if (apply_filters('edd_download_redirect_to_checkout', edd_straight_to_checkout(), $download->ID, $args)) {
        ?>
			<input type="hidden" name="edd_redirect_to_checkout" id="edd_redirect_to_checkout" value="1">
		<?php 
    }
    ?>

		<?php 
    do_action('edd_purchase_link_end', $download->ID, $args);
    ?>

	</form><!--end #<?php 
    echo esc_attr($form_id);
    ?>
-->
<?php 
    $purchase_form = ob_get_clean();
    return apply_filters('edd_purchase_download_form', $purchase_form, $args);
}
Пример #5
0
        foreach ($price as $row => $value) {
            if (is_object($post) && ($post->post_content == '[purchase_history]' || $post->post_content == '[downloads_history]') && $payment_id > 0) {
                if (isset($edd_options['expired'][$payment_id]) && $edd_options['expired'][$payment_id] == $download_id) {
                    if (!isset($value['renew'])) {
                        unset($price[$row]);
                    }
                }
            } else {
                if (isset($value['renew'])) {
                    unset($price[$row]);
                }
            }
        }
    }
    return $price;
}
//add_action( 'edd_purchase_variable_prices', 'edd_plans_filter_download_price', 900, 2 );
add_filter('edd_get_download_price', 'edd_plans_filter_download_price', 11, 2);
add_filter('edd_get_variable_prices', 'edd_plans_filter_download_price', 11, 2);
function edd_plans_filter_cart_price($price, $download_id, $options, $include_taxes = false)
{
    global $edd_options;
    $price = false;
    if (edd_has_variable_prices($download_id) && !empty($options)) {