/** * 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); }
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 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(); 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> '; $item .= '<span class="edd-cart-item-separator">-</span> ' . edd_currency_filter(edd_get_cart_item_price($id, $options)) . ' '; $item .= '<span class="edd-cart-item-separator">-</span> ' . $remove . '</li>'; return apply_filters('edd_cart_item', $item, $id); }
/** * Get the discounted amount on a price * * @since 1.9 * @param array $item Cart item array * @return float The discounted amount */ function edd_get_cart_item_discount_amount($item = array()) { global $edd_is_last_cart_item, $edd_flat_discount_total; // If we're not meeting the requirements of the $item array, return or set them if (empty($item) || empty($item['id'])) { return 0; } // Quantity is a requirement of the cart options array to determine the discounted price if (empty($item['quantity'])) { return 0; } if (!isset($item['options'])) { $item['options'] = array(); } $amount = 0; $price = edd_get_cart_item_price($item['id'], $item['options']); $discounted_price = $price; // Retrieve all discounts applied to the cart $discounts = edd_get_cart_discounts(); if ($discounts) { foreach ($discounts as $discount) { $code_id = edd_get_discount_id_by_code($discount); // Check discount exists if (!$code_id) { continue; } $reqs = edd_get_discount_product_reqs($code_id); $excluded_products = edd_get_discount_excluded_products($code_id); // Make sure requirements are set and that this discount shouldn't apply to the whole cart if (!empty($reqs) && edd_is_discount_not_global($code_id)) { // This is a product(s) specific discount foreach ($reqs as $download_id) { if ($download_id == $item['id'] && !in_array($item['id'], $excluded_products)) { $discounted_price -= $price - edd_get_discounted_amount($discount, $price); } } } else { // This is a global cart discount if (!in_array($item['id'], $excluded_products)) { if ('flat' === edd_get_discount_type($code_id)) { /* * * In order to correctly record individual item amounts, global flat rate discounts * are distributed across all cart items. The discount amount is divided by the number * of items in the cart and then a portion is evenly applied to each cart item */ $items_subtotal = 0.0; $cart_items = edd_get_cart_contents(); foreach ($cart_items as $cart_item) { if (!in_array($cart_item['id'], $excluded_products)) { $item_price = edd_get_cart_item_price($cart_item['id'], $cart_item['options']); $items_subtotal += $item_price * $cart_item['quantity']; } } $subtotal_percent = $price * $item['quantity'] / $items_subtotal; $code_amount = edd_get_discount_amount($code_id); $discounted_amount = $code_amount * $subtotal_percent; $discounted_price -= $discounted_amount; $edd_flat_discount_total += round($discounted_amount, edd_currency_decimal_filter()); if ($edd_is_last_cart_item && $edd_flat_discount_total < $code_amount) { $adjustment = $code_amount - $edd_flat_discount_total; $discounted_price -= $adjustment; } } else { $discounted_price -= $price - edd_get_discounted_amount($discount, $price); } } } } $amount = $price - apply_filters('edd_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price); if ('flat' !== edd_get_discount_type($code_id)) { $amount = $amount * $item['quantity']; } } return $amount; }
echo edd_get_cart_item_quantity($item['id'], $item['options']); ?> " /> <input type="hidden" name="edd-cart-downloads[]" value="<?php echo $item['id']; ?> " /> <input type="hidden" name="edd-cart-download-<?php echo $template_args['key']; ?> -options" value="<?php echo esc_attr(serialize($item['options'])); ?> " /> </label> <?php } ?> </div> <div class="checkout__price one-seventh medium-one-half small-one-fifth"> <?php echo esc_html(edd_currency_filter(edd_format_amount(edd_get_cart_item_price($item['id'], $item['options']) * edd_get_cart_item_quantity($item['id'], $item['options'])))); ?> <a href="<?php echo esc_url(edd_remove_item_url($template_args['key'])); ?> " class="button--naked checkout__cancel edd_cart_remove_item_btn"><span class="text-icon"></a> </div> </li> <?php
/** * Get Cart Content Details * * Retrieves the cart contnet details. * * @access public * @since 1.0 * @return array */ function edd_get_cart_content_details() { $cart_items = edd_get_cart_contents(); $details = array(); if ($cart_items) { foreach ($cart_items as $key => $item) { $details[$key] = array('name' => get_the_title($item['id']), 'id' => $item['id'], 'item_number' => $item, 'price' => edd_get_cart_item_price($item['id'], $item['options']), 'quantity' => 1); } } if (!empty($details)) { return $details; } return false; }
/** * Custom pledge level fix. * * If there is a custom price, figure out the difference * between that, and the price level they have chosen. Store * the differene in the cart item meta, so it can be added to * the total in the future. * * @since Astoundify Crowdfunding 1.6 * * @param array $cart_item The current cart item to be added. * @return array $cart_item The modified cart item. */ function atcf_edd_add_to_cart_item($cart_item) { if (isset($_POST['post_data'])) { $post_data = array(); parse_str($_POST['post_data'], $post_data); $custom_price = $post_data['atcf_custom_price']; } else { $custom_price = $_POST['atcf_custom_price']; } $custom_price = edd_sanitize_amount($custom_price); $price = edd_get_cart_item_price($cart_item['id'], $cart_item['options'], edd_prices_include_tax()); if ($custom_price > $price) { $cart_item['options']['atcf_extra_price'] = $custom_price - $price; } return $cart_item; }
/** * Retrieves the total discounted amount on the cart * * @since 1.4.1 * @param array $discounts Discount codes * @return float $discounted_amount Total discounted amount */ function edd_get_cart_discounted_amount($discounts = false) { if (empty($discounts)) { $discounts = edd_get_cart_discounts(); } // Setup the array of discounts if (!empty($_POST['edd-discount']) && empty($discounts)) { // Check for a posted discount $posted_discount = isset($_POST['edd-discount']) ? trim($_POST['edd-discount']) : false; if ($posted_discount) { $discounts = array(); $discounts[] = $posted_discount; } } // Return 0.00 if no discounts present if (empty($discounts)) { return 0.0; } $subtotal = edd_get_cart_subtotal($tax = false); $amounts = array(); $discounted_items = array(); foreach ($discounts as $discount) { $code_id = edd_get_discount_id_by_code($discount); $reqs = edd_get_discount_product_reqs($code_id); // Make sure requirements are set and that this discount shouldn't apply to the whole cart if (!empty($reqs) && edd_is_discount_not_global($code_id)) { // This is a product(s) specific discount $condition = edd_get_discount_product_condition($code_id); $cart_items = edd_get_cart_contents(); foreach ($reqs as $download_id) { if (edd_item_in_cart($download_id)) { $cart_key = edd_get_item_position_in_cart($download_id); $price = edd_get_cart_item_price($download_id, $cart_items[$cart_key]['options']); $amount = edd_get_discounted_amount($discount, $price); $discounted_items[] = $price - $amount; } } } else { // This is a global cart discount $subtotal = edd_get_cart_subtotal(); $amount = edd_get_discounted_amount($discount, $subtotal); $amounts[] = $subtotal - $amount; } } // Add up the total amount $discounted_amount = 0.0; $item_discount = array_sum($discounted_items); $global_discount = array_sum($amounts); $discounted_amount += $item_discount; $discounted_amount += $global_discount; return apply_filters('edd_get_cart_discounted_amount', edd_sanitize_amount($discounted_amount)); }
/** * 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); }
if (current_theme_supports('post-thumbnails')) { if (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'])) { $item_title .= ' - ' . edd_get_price_name($item['id'], $item['options']); } echo '<span class="edd_checkout_cart_item_title">' . esc_html($item_title) . '</span>'; ?> </td> <td class="edd_cart_item_price"><?php echo esc_html(edd_currency_filter(edd_get_cart_item_price($item['id'], $item['options']))); ?> </td> <td class="edd_cart_actions"><a href="<?php echo esc_url(edd_remove_item_url($key, $post)); ?> "><?php _e('remove', 'edd'); ?> </a></td> <?php do_action('edd_checkout_table_body_last', $item); ?> </tr> <?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 = ' – '; 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; }
/** * Total price of items in wish list * * Used on front end and also admin * @since 1.0 * @param $list_id ID of list * @todo update total as items are removed from list via ajax */ function edd_wl_get_list_total($list_id) { // get contents of cart $list_items = get_post_meta($list_id, 'edd_wish_list', true); $total = array(); if ($list_items) { foreach ($list_items as $item) { $item_price = edd_get_cart_item_price($item['id'], $item['options']); $item_price = round($item_price, 2); $total[] = $item_price; } } // add up values $total = array_sum($total); $total = esc_html(edd_currency_filter(edd_format_amount($total))); return apply_filters('edd_wl_list_total', $total); }
function eddpdfi_pdf_template_vat($eddpdfi_pdf, $eddpdfi_payment, $eddpdfi_payment_meta, $eddpdfi_buyer_info, $eddpdfi_payment_gateway, $eddpdfi_payment_method, $address_line_2_line_height, $company_name, $eddpdfi_payment_date, $eddpdfi_payment_status) { global $edd_options; if (!isset($edd_options['eddpdfi_templates'])) { $edd_options['eddpdfi_templates'] = 'default'; } $color = empty($edd_options['edd_vat_pdf_colors']) ? "blue" : $edd_options['edd_vat_pdf_colors']; switch ($color) { case 'blue': $colors = array('body' => array(8, 75, 110), 'emphasis' => array(71, 155, 198), 'title' => array(0, 127, 192), 'header' => array(202, 226, 238), 'sub' => array(234, 242, 245), 'border' => array(166, 205, 226), 'notes' => array(7, 46, 66)); break; case 'red': $colors = array('body' => array(110, 8, 8), 'emphasis' => array(198, 71, 71), 'title' => array(192, 0, 0), 'header' => array(238, 202, 202), 'sub' => array(245, 243, 243), 'border' => array(226, 166, 166), 'notes' => array(66, 7, 7)); break; case 'green': $colors = array('body' => array(8, 110, 39), 'emphasis' => array(71, 198, 98), 'title' => array(0, 192, 68), 'header' => array(202, 238, 212), 'sub' => array(243, 245, 244), 'border' => array(166, 226, 179), 'notes' => array(7, 66, 28)); break; case 'orange': $colors = array('body' => array(110, 54, 8), 'emphasis' => array(198, 134, 71), 'title' => array(192, 81, 0), 'header' => array(238, 219, 202), 'sub' => array(245, 245, 243), 'border' => array(226, 224, 166), 'notes' => array(65, 66, 7)); break; case 'yellow': $colors = array('body' => array(109, 110, 8), 'emphasis' => array(197, 198, 71), 'title' => array(192, 190, 0), 'header' => array(238, 238, 202), 'sub' => array(245, 244, 243), 'border' => array(226, 193, 166), 'notes' => array(66, 38, 7)); break; case 'purple': $colors = array('body' => array(66, 8, 110), 'emphasis' => array(137, 71, 198), 'title' => array(72, 0, 192), 'header' => array(208, 202, 238), 'sub' => array(244, 243, 245), 'border' => array(189, 166, 226), 'notes' => array(35, 7, 66)); break; case 'pink': $colors = array('body' => array(110, 8, 82), 'emphasis' => array(198, 71, 152), 'title' => array(92, 0, 65), 'header' => array(238, 202, 232), 'sub' => array(245, 243, 245), 'border' => array(226, 166, 213), 'notes' => array(66, 7, 51)); break; } $eddpdfi_pdf->AddFont('opensans', ''); $eddpdfi_pdf->AddFont('opensansb', ''); $font = isset($edd_options['eddpdfi_enable_char_support']) ? 'freesans' : 'opensans'; $fontb = isset($edd_options['eddpdfi_enable_char_support']) ? 'freesans' : 'opensansb'; $eddpdfi_pdf->SetMargins(8, 8, 8); $eddpdfi_pdf->SetX(8); $eddpdfi_pdf->AddPage(); $eddpdfi_pdf->Ln(5); $eddpdfi_logo_size = 0; if (isset($eddpdfi_logo_size) && isset($edd_options['eddpdfi_logo_upload']) && !empty($edd_options['eddpdfi_logo_upload'])) { // $file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array() $eddpdfi_pdf->Image($edd_options['eddpdfi_logo_upload'], 8, 10, 0, '25', '', false, 'LTR', false, 96); } else { $eddpdfi_pdf->SetFont($font, '', 22); $eddpdfi_pdf->SetTextColor(50, 50, 50); $eddpdfi_pdf->Cell(0, 0, $company_name, 0, 2, 'L', false); } $eddpdfi_pdf->SetFont($font, '', 18); $eddpdfi_pdf->SetTextColor($colors['title'][0], $colors['title'][1], $colors['title'][2]); $eddpdfi_pdf->SetY(45); if ($eddpdfi_payment_status === 'Refunded') { $eddpdfi_pdf->Cell(0, 0, 'Invoice Correction', 0, 2, 'L', false); } else { $eddpdfi_pdf->Cell(0, 0, __('Invoice', 'eddpdfi'), 0, 2, 'L', false); } $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->SetXY(8, 60); $eddpdfi_pdf->SetFont($fontb, '', 10); $eddpdfi_pdf->Cell(0, 6, __('From', 'eddpdfi'), 0, 2, 'L', false); $eddpdfi_pdf->SetFont($font, '', 10); if (!empty($edd_options['edd_vat_company_name'])) { $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['edd_vat_company_name']), $edd_options['edd_vat_company_name'], 0, 2, 'L', false); } if (!empty($edd_options['eddpdfi_name'])) { $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['eddpdfi_name']), eddpdfi_get_settings($eddpdfi_pdf, 'name'), 0, 2, 'L', false); } if (!empty($edd_options['eddpdfi_address_line1'])) { $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['eddpdfi_address_line1']), eddpdfi_get_settings($eddpdfi_pdf, 'addr_line1'), 0, 2, 'L', false); } if (!empty($edd_options['eddpdfi_address_line2'])) { $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['eddpdfi_address_line2']), eddpdfi_get_settings($eddpdfi_pdf, 'addr_line2'), 0, 2, 'L', false); } if (!empty($edd_options['eddpdfi_address_city_state_zip'])) { $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['eddpdfi_address_city_state_zip']), eddpdfi_get_settings($eddpdfi_pdf, 'city_state_zip'), 0, 2, 'L', false); } if (!empty($edd_options['base_country'])) { $countries = edd_get_country_list(); $countries['UK'] = $countries['GB']; $country = $countries[$edd_options['base_country']]; $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($country), $country, 0, 2, 'L', false); } if (!empty($edd_options['eddpdfi_email_address'])) { $eddpdfi_pdf->SetTextColor(41, 102, 152); $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['eddpdfi_email_address']), eddpdfi_get_settings($eddpdfi_pdf, 'email'), 0, 2, 'L', false); } if (isset($edd_options['eddpdfi_url']) && $edd_options['eddpdfi_url']) { $eddpdfi_pdf->SetTextColor(41, 102, 152); $eddpdfi_pdf->Cell(0, 6, get_option('siteurl'), 0, 2, 'L', false); } if (!empty($edd_options['edd_vat_number'])) { $vat_number = maybe_unserialize($edd_options['edd_vat_number']); if (!empty($vat_number['number'])) { //$vat_number = __(sprintf('%s ID ', apply_filters('lsl_tax_label','Tax')), 'edd_vat') . $vat_number['number']; $vat_number = 'VAT No. ' . $vat_number['number']; $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($vat_number), $vat_number, 0, 2, 'L', false); } } $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->Ln(12); $eddpdfi_pdf->Ln(); $eddpdfi_pdf->SetXY(60, 60); $eddpdfi_pdf->SetFont($fontb, '', 10); $eddpdfi_pdf->Cell(0, 6, __('To', 'eddpdfi'), 0, 2, 'L', false); $eddpdfi_pdf->SetFont($font, '', 10); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_buyer_info['first_name'] . ' ' . $eddpdfi_buyer_info['last_name'], 0, 2, 'L', false); $eddpdfi_pdf->SetTextColor(41, 102, 152); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_payment_meta['email'], 0, 2, 'L', false); $eddpdfi_pdf->SetTextColor(50, 50, 50); $eddpdfi_pdf->Ln(4); $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetTextColor($colors['emphasis'][0], $colors['emphasis'][1], $colors['emphasis'][2]); $eddpdfi_pdf->Cell(30, 6, __('Invoice Date', 'eddpdfi'), 0, 0, 'L', false); $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_payment_date, 0, 2, 'L', false); $eddpdfi_pdf->SetXY(60, 92); $eddpdfi_pdf->SetTextColor($colors['emphasis'][0], $colors['emphasis'][1], $colors['emphasis'][2]); $eddpdfi_pdf->Cell(30, 6, __('Invoice ID', 'eddpdfi'), 0, 0, 'L', false); $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); if (function_exists('eddpdfi_get_payment_number') && isset($edd_options['edd_vat_invoice_number'])) { $eddpdfi_pdf->Cell(0, 6, eddpdfi_get_payment_number($eddpdfi_payment->ID), 0, 2, 'L', false); } else { $eddpdfi_pdf->Cell(0, 6, '#' . $eddpdfi_payment->ID, 0, 2, 'L', false); } $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetTextColor($colors['emphasis'][0], $colors['emphasis'][1], $colors['emphasis'][2]); $eddpdfi_pdf->Cell(30, 6, __('Purchase Key', 'eddpdfi'), 0, 0, 'L', false); $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_payment_meta['key'], 0, 2, 'L', false); $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetTextColor($colors['emphasis'][0], $colors['emphasis'][1], $colors['emphasis'][2]); $eddpdfi_pdf->Cell(30, 6, __('Payment Status', 'eddpdfi'), 0, 0, 'L', false); $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_payment_status, 0, 2, 'L', false); $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetTextColor($colors['emphasis'][0], $colors['emphasis'][1], $colors['emphasis'][2]); $eddpdfi_pdf->Cell(30, 6, __('Payment Method', 'eddpdfi'), 0, 0, 'L', false); $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_payment_method, 0, 2, 'L', false); $offset = apply_filters('eddpdfi_pdf_template_extra_fields', 0, 'color', $eddpdfi_pdf, $eddpdfi_payment, $eddpdfi_payment_meta, $eddpdfi_buyer_info, $colors); $eddpdfi_pdf->SetXY(61, 120 + $offset); $eddpdfi_pdf->SetFillColor($colors['header'][0], $colors['header'][1], $colors['header'][2]); $eddpdfi_pdf->SetDrawColor($colors['border'][0], $colors['border'][1], $colors['border'][2]); $eddpdfi_pdf->SetFont($fontb, '', 10); $eddpdfi_pdf->Cell(140, 8, __('Invoice Items', 'eddpdfi'), 1, 2, 'C', true); $eddpdfi_pdf->Ln(0.2); $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->SetFillColor($colors['sub'][0], $colors['sub'][1], $colors['sub'][2]); $eddpdfi_pdf->SetFont($font, '', 9); $qenabled = version_compare(EDD_VERSION, "1.9") >= 0 ? true : (function_exists('edd_item_quanities_enabled') ? edd_item_quanities_enabled() : false); $eddpdfi_pdf->Cell($qenabled ? 95 : 102, 7, __('PRODUCT NAME', 'eddpdfi'), 'BL', 0, 'L', true); if ($qenabled) { $eddpdfi_pdf->Cell(10, 7, __('#', 'eddpdfi'), 'B', 0, 0, true); } $eddpdfi_pdf->Cell($qenabled ? 35 : 38, 7, __('PRICE', 'eddpdfi'), 'BR', 0, 'R', true); $eddpdfi_pdf->Ln(0.2); $eddpdfi_pdf_downloads = isset($eddpdfi_payment_meta['cart_details']) ? maybe_unserialize($eddpdfi_payment_meta['cart_details']) : false; $eddpdfi_pdf->Ln(); if ($eddpdfi_pdf_downloads) { $eddpdfi_pdf->SetX(61); $includes_taxes = edd_prices_include_tax(); foreach ($eddpdfi_pdf_downloads as $key => $download) { $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->SetFont($font, '', 10); $eddpdfi_download_id = isset($eddpdfi_payment_meta['cart_details']) ? $download['id'] : $download; $eddpdfi_price_override = isset($eddpdfi_payment_meta['cart_details']) ? $download['price'] : null; $user_info = maybe_unserialize($eddpdfi_payment_meta['user_info']); $eddpdfi_final_download_price = edd_get_download_final_price($eddpdfi_download_id, $user_info, $eddpdfi_price_override); if (isset($user_info['discount']) && $user_info['discount'] != 'none') { $eddpdfi_discount = $user_info['discount']; } else { $eddpdfi_discount = __('None', 'eddpdfi'); } // $eddpdfi_total_price = html_entity_decode( edd_currency_filter( edd_format_amount( $eddpdfi_payment_meta['amount'] ) ) ); $eddpdfi_download_title = html_entity_decode(get_the_title($eddpdfi_download_id), ENT_COMPAT, 'UTF-8'); if (edd_has_variable_prices($eddpdfi_download_id)) { $eddpdfi_download_title .= ' - ' . edd_get_cart_item_price_name($download); $options = $download['item_number']['options']; } // error_log(print_r($download,true)); $options['is_item'] = $eddpdfi_download_id; $price = edd_get_cart_item_price($eddpdfi_download_id, $options, $includes_taxes); $eddpdfi_download_price = ' ' . html_entity_decode(edd_currency_filter(edd_format_amount($price)), ENT_COMPAT, 'UTF-8'); // $eddpdfi_download_price = ' ' . html_entity_decode( edd_currency_filter( edd_format_amount( $eddpdfi_final_download_price ) ), ENT_COMPAT, 'UTF-8' ); $eddpdfi_pdf->Cell($qenabled ? 95 : 102, 8, $eddpdfi_download_title, 'B', 0, 'L', false); if ($qenabled) { $quantity = is_array($download) ? $download['quantity'] : 1; $eddpdfi_pdf->Cell(10, 8, $quantity, 'B', 0, 'C', false); } $eddpdfi_pdf->Cell($qenabled ? 35 : 38, 8, $eddpdfi_download_price, 'B', 2, 'R', false); } $eddpdfi_pdf->Ln(5); $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->SetFillColor($colors['header'][0], $colors['header'][1], $colors['header'][2]); $eddpdfi_pdf->SetFont($fontb, '', 10); $eddpdfi_pdf->Cell(140, 8, __('Invoice Totals', 'eddpdfi'), 1, 2, 'C', true); $eddpdfi_pdf->Ln(0.2); $eddpdfi_pdf->SetX(61); if (edd_use_taxes()) { //$taxrate = (edd_get_payment_amount( $eddpdfi_payment->ID ) - round(edd_get_payment_subtotal( $eddpdfi_payment->ID ))) / round(edd_get_payment_subtotal( $eddpdfi_payment->ID )) * 100; switch ($eddpdfi_buyer_info['address']['country']) { case 'BE': $taxrate = '21%'; break; case 'BG': $taxrate = '20%'; break; case 'CZ': $taxrate = '21%'; break; case 'DK': $taxrate = '25%'; break; case 'GB': $taxrate = '20%'; break; case 'UK': $taxrate = '20%'; break; case 'DE': $taxrate = '19%'; break; case 'EE': $taxrate = '20%'; break; case 'EL': $taxrate = '23%'; break; case 'ES': $taxrate = '21%'; break; case 'FR': $taxrate = '20%'; break; case 'HR': $taxrate = '25%'; break; case 'IE': $taxrate = '23%'; break; case 'IT': $taxrate = '22%'; break; case 'CY': $taxrate = '19%'; break; case 'LV': $taxrate = '21%'; break; case 'LT': $taxrate = '21%'; break; case 'LU': $taxrate = '17%'; break; case 'HU': $taxrate = '27%'; break; case 'MT': $taxrate = '18%'; break; case 'NL': $taxrate = '21%'; break; case 'AT': $taxrate = '20%'; break; case 'PL': $taxrate = '23%'; break; case 'PT': $taxrate = '23%'; break; case 'RO': $taxrate = '24%'; break; case 'SI': $taxrate = '22%'; break; case 'SK': $taxrate = '20%'; break; case 'FI': $taxrate = '24%'; break; case 'SE': $taxrate = '25%'; break; default: $taxrate = '0%'; } $eddpdfi_pdf->Cell(102, 8, __('Subtotal', 'eddpdfi'), 'B', 0, 'L', false); $eddpdfi_pdf->Cell(38, 8, html_entity_decode(edd_payment_subtotal($eddpdfi_payment->ID), ENT_COMPAT, 'UTF-8'), 'B', 2, 'R', false); $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->Cell(102, 8, __(apply_filters('lsl_tax_label', 'Tax'), 'eddpdfi'), 'B', 0, 'L', false); $eddpdfi_pdf->Cell(38, 8, html_entity_decode(edd_payment_tax($eddpdfi_payment->ID), ENT_COMPAT, 'UTF-8'), 'B', 2, 'R', false); $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->Cell(102, 8, __('VAT RATE', 'eddpdfi'), 'B', 0, 'L', false); $eddpdfi_pdf->Cell(38, 8, $taxrate, 'B', 2, 'R', false); } $fees = edd_get_payment_fees($eddpdfi_payment->ID); if (!empty($fees)) { foreach ($fees as $fee) { $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->Cell(102, 8, $fee['label'], 'B', 0, 'L', false); $eddpdfi_pdf->Cell(38, 8, html_entity_decode(edd_currency_filter($fee['amount']), ENT_COMPAT, 'UTF-8'), 'B', 2, 'R', true); } } if ($eddpdfi_discount !== __('None', 'eddpdfi')) { $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->Cell(102, 8, __('Discount Used', 'eddpdfi'), 'B', 0, 'L', false); $eddpdfi_pdf->Cell(38, 8, $eddpdfi_discount, 'B', 2, 'R', false); } $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->SetFont($fontb, '', 11); $eddpdfi_pdf->Cell(102, 10, __('Total Due', 'eddpdfi'), 'B', 0, 'L', false); if ($eddpdfi_payment_status === 'Refunded') { $eddpdfi_pdf->Cell(38, 10, '-' . html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_payment_amount($eddpdfi_payment->ID))), ENT_COMPAT, 'UTF-8'), 'B', 2, 'R', false); } else { $eddpdfi_pdf->Cell(38, 10, html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_payment_amount($eddpdfi_payment->ID))), ENT_COMPAT, 'UTF-8'), 'B', 2, 'R', false); } $eddpdfi_pdf->Ln(10); if (isset($edd_options['eddpdfi_additional_notes']) && !empty($edd_options['eddpdfi_additional_notes'])) { $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetFont($font, '', 13); $eddpdfi_pdf->Cell(0, 6, __('Additional Notes', 'eddpdfi'), 0, 2, 'L', false); $eddpdfi_pdf->Ln(2); $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetFont($font, '', 10); $eddpdfi_pdf->SetTextColor($colors['notes'][0], $colors['notes'][1], $colors['notes'][2]); $eddpdfi_pdf->MultiCell(0, 6, eddpdfi_get_settings($eddpdfi_pdf, 'notes'), 0, 'L', false); } } }
function edd_downloads_upgrade_to_cart($item) { $post_data = urldecode($_REQUEST['post_data']); $post_data_formated = array(); if (strstr($post_data, "upgrade_license") && strstr($post_data, "upgrade_product_to")) { $post_data_split = explode("&", $post_data); foreach ($post_data_split as $data_split) { $data_array = explode("=", $data_split); $post_data_formated[$data_array[0]] = $data_array[1]; } } if (isset($post_data_formated['upgrade_license']) && isset($post_data_formated['upgrade_product_to'])) { $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : 0; $download_files = edd_get_download_files($post_data_formated['upgrade_product_to'], $price_id); $post_meta = get_post_meta(absint($post_data_formated['upgrade_license']), '_edd_sl_download_id', true); $old_price_id = get_post_meta(absint($post_data_formated['upgrade_license']), '_edd_sl_download_price_id', true); $old_download_file = edd_get_download_files($post_meta, $old_price_id); $item['upgrade'] = array(); $item['upgrade']['old_product'] = absint($post_data_formated['old_product']); $item['upgrade']['new_attachment_id'] = isset($download_files[0]['attachment_id']) ? absint($download_files[0]['attachment_id']) : 0; $item['upgrade']['old_attachment_id'] = isset($old_download_file[0]['attachment_id']) ? absint($old_download_file[0]['attachment_id']) : 0; $item['upgrade']['upgrade_license'] = absint($post_data_formated['upgrade_license']); $item['upgrade']['upgrade_product_to'] = absint($post_data_formated['upgrade_product_to']); if (isset($item['options']) && !empty($item['options'])) { $item['upgrade']['options'] = $item['options']; } $old_product_price = edd_get_cart_item_price(absint($post_data_formated['old_product']), $item['options']); $new_product_price = edd_get_cart_item_price(absint($post_data_formated['upgrade_product_to']), $item['options']); $item['upgrade']['upgrade_price'] = edd_format_amount($new_product_price - $old_product_price); //edd_get_cart_item_price( absint($post_data_formated['upgrade_product_to']), $item['options'] ); $payment_id_lic = get_post_meta($post_data_formated['upgrade_license'], '_edd_sl_payment_id', true); $item['upgrade']['upgrade_product_used'] = 0; $session = edd_get_purchase_session(); $payment_key = edd_get_payment_key(absint($payment_id_lic)); $session['purchase_key'] = $payment_key; edd_set_purchase_session($session); EDD()->session->set('upgrade_license', $payment_key); } return $item; }
/** * Retrieve the Cart Content Details * * @since 1.0 * @return array $defailt Cart content details */ function edd_get_cart_content_details() { $cart_items = edd_get_cart_contents(); if (empty($cart_items)) { return false; } $details = array(); $is_taxed = edd_is_cart_taxed(); foreach ($cart_items as $key => $item) { $price = edd_get_cart_item_price($item['id'], $item['options']); $non_taxed_price = edd_get_cart_item_price($item['id'], $item['options'], false); $details[$key] = array('name' => get_the_title($item['id']), 'id' => $item['id'], 'item_number' => $item, 'price' => $price, 'quantity' => 1, 'tax' => $is_taxed ? edd_calculate_tax($non_taxed_price, false) : 0); } return $details; }
/** * 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); }
/** * Calculate Total Bought Points * * Handles to calculate total bought * points for cart data * * @package Easy Digital Downloads - Points and Rewards * @since 1.1.0 **/ public function edd_points_get_bought_points($cartdata) { $points = 0; //check cart not empty if (!empty($cartdata)) { //calculate bought price foreach ($cartdata as $items) { //check download type is points if (edd_get_download_type($items['id']) == 'points') { //check item of options set then consider that if (isset($items['options'])) { $itemoptions = $items['options']; } elseif (isset($items['item_number']['options'])) { $itemoptions = $items['item_number']['options']; } else { $itemoptions = array(); } //get cart item price $downloadprice = edd_get_cart_item_price($items['id'], $itemoptions) * $items['quantity']; //get buy points from download $points += $this->edd_points_get_download_buy_points($downloadprice); } //end if to check download type is points } //end foreach loop } //check cart data should not empty //return points return $points; }
/** * Get the discounted amount on a price * * @since 1.9 * @param array $item Cart item array * @return float The discounted amount */ function edd_get_cart_item_discount_amount($item = array()) { $amount = 0; $price = edd_get_cart_item_price($item['id'], $item['options'], edd_prices_include_tax()); $discounted_price = $price; // Retrieve all discounts applied to the cart $discounts = edd_get_cart_discounts(); if ($discounts) { foreach ($discounts as $discount) { $code_id = edd_get_discount_id_by_code($discount); $reqs = edd_get_discount_product_reqs($code_id); $excluded_products = edd_get_discount_excluded_products($code_id); // Make sure requirements are set and that this discount shouldn't apply to the whole cart if (!empty($reqs) && edd_is_discount_not_global($code_id)) { // This is a product(s) specific discount foreach ($reqs as $download_id) { if ($download_id == $item['id'] && !in_array($item['id'], $excluded_products)) { $discounted_price -= $price - edd_get_discounted_amount($discount, $price); } } } else { // This is a global cart discount if (!in_array($item['id'], $excluded_products)) { if ('flat' === edd_get_discount_type($code_id)) { /* * * In order to correctly record individual item amounts, global flat rate discounts * are distributed across all cart items. The discount amount is divided by the number * of items in the cart and then a portion is evenly applied to each cart item */ $discounted_amount = edd_get_discount_amount($code_id); $discounted_amount = $discounted_amount / edd_get_cart_quantity(); $discounted_price -= $discounted_amount; } else { $discounted_price -= $price - edd_get_discounted_amount($discount, $price); } } } } $amount = $price - apply_filters('edd_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price); if ('flat' !== edd_get_discount_type($code_id)) { $amount = $amount * $item['quantity']; } } return $amount; }