function download_checkout_item_total_function($atts) { $atts = shortcode_atts(array('id' => ''), $atts, 'download_checkout_item_total'); global $x, $cart_array; if ($atts['id'] != '') { $id = $atts['id']; } else { $id = get_the_id(); } $options = $cart_array[get_the_ID()][$x - 1]['options']; $price = edd_get_cart_item_price($id, $options); $price += edd_get_cart_item_tax($id, $options, $price); $price = edd_currency_filter(edd_format_amount($price)); return $price; }
/** * Get Cart Item Price * * @since 1.0 * * @param int $item_id Download (cart item) ID number * @param array $options Optional parameters, used for defining variable prices * @return string Fully formatted price */ function edd_cart_item_price($item_id = 0, $options = array()) { $price = edd_get_cart_item_price($item_id, $options); $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()) { $price += edd_get_cart_item_tax($item_id, $options, $price); } if (!edd_prices_show_tax_on_checkout() && edd_prices_include_tax()) { $price -= edd_get_cart_item_tax($item_id, $options, $price); } if (edd_display_tax_rate()) { $label = ' – '; 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); } } $price = edd_currency_filter(edd_format_amount($price)); return apply_filters('edd_cart_item_price_label', $price . $label, $item_id, $options); }
/** * Get Cart Item Price * * Gets the price of the cart item. Always exclusive of taxes * * Do not use this for getting the final price (with taxes and discounts) of an item. * Use edd_get_cart_item_final_price() * * @since 1.0 * @param int $download_id Download ID number * @param array $options Optional parameters, used for defining variable prices * @param bool $remove_tax_from_inclusive Remove the tax amount from tax inclusive priced products. * @return float|bool Price for this item */ function edd_get_cart_item_price($download_id = 0, $options = array(), $remove_tax_from_inclusive = false) { $price = 0; $variable_prices = edd_has_variable_prices($download_id); if ($variable_prices) { $prices = edd_get_variable_prices($download_id); if ($prices) { if (!empty($options)) { $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; } else { $price = false; } } } if (!$variable_prices || false === $price) { // Get the standard Download price if not using variable prices $price = edd_get_download_price($download_id); } if ($remove_tax_from_inclusive && edd_prices_include_tax()) { $price -= edd_get_cart_item_tax($download_id, $options, $price); } return apply_filters('edd_cart_item_price', $price, $download_id, $options); }
/** * Get Cart Item Price * * @since 1.0 * * @param int $item_id Download (cart item) ID number * @param array $options Optional parameters, used for defining variable prices * @return string Fully formatted price */ function edd_cart_item_price($item_id = 0, $options = array()) { global $edd_options; $price = edd_get_cart_item_price($item_id, $options); $label = ''; if (edd_prices_show_tax_on_checkout() && !edd_prices_include_tax()) { $price += edd_get_cart_item_tax($item_id, $options, $price); } if (!edd_prices_show_tax_on_checkout() && edd_prices_include_tax()) { $price -= edd_get_cart_item_tax($item_id, $options, $price); } $price = edd_currency_filter(edd_format_amount($price)); if (edd_display_tax_rate()) { $label = ' – '; 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()); } } return esc_html($price . $label); }
/** * 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 = ' – '; 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; }