/** * Adds item to the cart from the wish list via AJAX. Based off edd_ajax_add_to_cart() * * @since 1.0 * @return void */ function edd_ajax_add_to_cart_from_wish_list() { if (isset($_POST['download_id'])) { global $post; $to_add = array(); if (isset($_POST['price_ids']) && is_array($_POST['price_ids'])) { foreach ($_POST['price_ids'] as $price) { $to_add[] = array('price_id' => $price); } } foreach ($to_add as $options) { if ($_POST['download_id'] == $options['price_id']) { $options = array(); } parse_str($_POST['post_data'], $post_data); if (isset($options['price_id']) && isset($post_data['edd_download_quantity_' . $options['price_id']])) { $options['quantity'] = absint($post_data['edd_download_quantity_' . $options['price_id']]); } else { $options['quantity'] = isset($post_data['edd_download_quantity']) ? absint($post_data['edd_download_quantity']) : 1; } // call EDD's edd_add_to_cart function $key = edd_add_to_cart($_POST['download_id'], $options); $item = array('id' => $_POST['download_id'], 'options' => $options); $item = apply_filters('edd_wl_ajax_pre_cart_item_template', $item); $return = array('add_to_cart' => 'Added to Cart', 'subtotal' => html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())), ENT_COMPAT, 'UTF-8'), 'cart_item' => html_entity_decode(edd_get_cart_item_template($key, $item, true), ENT_COMPAT, 'UTF-8')); echo json_encode($return); } } edd_die(); }
/** * Process Purchase Form * * Handles the purchase form process. * * @access private * @since 1.0 * @return void */ function edd_process_purchase_form() { do_action('edd_pre_process_purchase'); // Make sure the cart isn't empty if (!edd_get_cart_contents() && !edd_cart_has_fees()) { $valid_data = false; edd_set_error('empty_cart', __('Your cart is empty', 'easy-digital-downloads')); } else { // Validate the form $_POST data $valid_data = edd_purchase_form_validate_fields(); // Allow themes and plugins to hook to errors do_action('edd_checkout_error_checks', $valid_data, $_POST); } $is_ajax = isset($_POST['edd_ajax']); // Process the login form if (isset($_POST['edd_login_submit'])) { edd_process_purchase_login(); } // Validate the user $user = edd_get_purchase_form_user($valid_data); if (false === $valid_data || edd_get_errors() || !$user) { if ($is_ajax) { do_action('edd_ajax_checkout_errors'); edd_die(); } else { return false; } } if ($is_ajax) { echo 'success'; edd_die(); } // Setup user information $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount'], 'address' => $user['address']); $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; // Setup purchase information $purchase_data = array('downloads' => edd_get_cart_contents(), 'fees' => edd_get_cart_fees(), 'subtotal' => edd_get_cart_subtotal(), 'discount' => edd_get_cart_discounted_amount(), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_total(), 'purchase_key' => strtolower(md5($user['user_email'] . date('Y-m-d H:i:s') . $auth_key . uniqid('edd', true))), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s', current_time('timestamp')), 'user_info' => stripslashes_deep($user_info), 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']); // Add the user data for hooks $valid_data['user'] = $user; // Allow themes and plugins to hook before the gateway do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data); // If the total amount in the cart is 0, send to the manual gateway. This emulates a free download purchase if (!$purchase_data['price']) { // Revert to manual $purchase_data['gateway'] = 'manual'; $_POST['edd-gateway'] = 'manual'; } // Allow the purchase data to be modified before it is sent to the gateway $purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data); // Setup the data we're storing in the purchase session $session_data = $purchase_data; // Make sure credit card numbers are never stored in sessions unset($session_data['card_info']['card_number']); // Used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data. edd_set_purchase_session($session_data); // Send info to the gateway for payment processing edd_send_to_gateway($purchase_data['gateway'], $purchase_data); edd_die(); }
/** * Process Purchase Form * * Handles the purchase form process. * * @access private * @since 1.0 * @version 1.0.8.1 * @return void */ function edd_process_purchase_form() { // Make sure the cart isn't empty if (!edd_get_cart_contents()) { edd_set_error('empty_cart', __('Your cart is empty', 'edd')); } else { // Validate the form $_POST data $valid_data = edd_purchase_form_validate_fields(); // Allow themes and plugins to hoook to errors do_action('edd_checkout_error_checks', $valid_data, $_POST); } $is_ajax = isset($_POST['edd_ajax']); $user = edd_get_purchase_form_user($valid_data); if (edd_get_errors() || !$user) { if ($is_ajax) { do_action('edd_ajax_checkout_errors'); edd_die(); } else { return false; } } if ($is_ajax) { echo 'success'; edd_die(); } // Setup user information $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount']); // Setup purchase information $purchase_data = array('downloads' => edd_get_cart_contents(), 'fees' => edd_get_cart_fees(), 'subtotal' => edd_get_cart_subtotal(), 'discount' => edd_get_cart_discounted_amount(), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_total(), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s'), 'user_info' => $user_info, 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']); // Add the user data for hooks $valid_data['user'] = $user; // Allow themes and plugins to hook before the gateway do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data); // Allow the purchase data to be modified before it is sent to the gateway $purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data); // If the total amount in the cart is 0, send to the manaul gateway. This emulates a free download purchase if (!$purchase_data['price']) { // Revert to manual $valid_data['gateway'] = 'manual'; } // Used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data. edd_set_purchase_session($purchase_data); // Send info to the gateway for payment processing edd_send_to_gateway($valid_data['gateway'], $purchase_data); edd_die(); }
<?php if (edd_use_taxes()) { ?> <li class="cart_item edd-cart-meta edd_subtotal"><?php echo __('Subtotal:', 'easy-digital-downloads') . " <span class='subtotal'>" . edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())); ?> </span></li> <li class="cart_item edd-cart-meta edd_cart_tax"><?php _e('Estimated Tax:', 'easy-digital-downloads'); ?> <span class="cart-tax"><?php echo edd_currency_filter(edd_format_amount(edd_get_cart_tax())); ?> </span></li> <?php } ?> <li class="cart_item edd-cart-meta edd_total"><?php _e('Total:', 'easy-digital-downloads'); ?> <span class="cart-total"><?php echo edd_currency_filter(edd_format_amount(edd_get_cart_total())); ?> </span></li> <li class="cart_item edd_checkout"><a href="<?php echo edd_get_checkout_uri(); ?> "><?php _e('Checkout', 'easy-digital-downloads'); ?>
/** * Gets the total tax amount for the cart contents * * @access public * @since 1.2.3 * @return string */ function edd_get_cart_tax() { if (!edd_use_taxes()) { return 0; } $cart_sub_total = edd_get_cart_subtotal(); $cart_tax = edd_calculate_tax($cart_sub_total); $cart_tax = number_format($cart_tax, 2); return apply_filters('edd_get_cart_tax', $cart_tax, $cart_sub_total); }
/** * Get Total Cart Amount * * Returns amount after taxes and discounts * * @since 1.4.1 * @param bool $discounts Array of discounts to apply (needed during AJAX calls) * @return float Cart amount */ function edd_get_cart_total($discounts = false) { $subtotal = edd_get_cart_subtotal(); $discounts = edd_get_cart_discounted_amount(); $cart_tax = edd_get_cart_tax(); $fees = edd_get_cart_fee_total(); $total = $subtotal - $discounts + $cart_tax + $fees; if ($total < 0) { $total = 0.0; } return (double) apply_filters('edd_get_cart_total', $total); }
?> <?php if (edd_use_taxes() && cart_has_tax()) { ?> <hr class="hr--no-pointer tight"> <div class="row iceberg--small"> <div class="grid"> <div class="three-seventh offset-three-seventh small-four-fifth"><?php _e('Subtotal', 'yoastcom'); ?> </div> <div class="one-seventh small-one-fifth edd_cart_subtotal_amount"> <?php echo esc_html(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal() - edd_get_cart_discounted_amount()))); ?> </div> </div> </div> <?php if (!edd_prices_show_tax_on_checkout()) { ?> <div class="row iceberg--small"> <div class="grid"> <div class="three-seventh offset-three-seventh small-four-fifth"> <?php printf(__('VAT (<span class="yst-tax-rate">%s</span>%%)', 'yoastcom'), number_format(edd_get_tax_rate() * 100, 1)); ?> </div>
<li class="cart_item empty"><?php echo edd_empty_cart_message(); ?> </li> <li class="cart_item edd_subtotal" style="display:none;"><?php echo __('Subtotal:', 'edd') . " <span class='subtotal'>" . edd_currency_filter(edd_get_cart_subtotal()); ?> </span></li> <li class="cart_item edd_checkout" style="display:none;"><a href="<?php echo edd_get_checkout_uri(); ?> "><?php _e('Checkout', 'edd'); ?> </a></li>
<li class="cart_item edd_subtotal"> <span> <?php echo __('Subtotal:', 'edd'); ?> <span class="price"> <?php echo edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())); ?> </span> </span> <a href="<?php echo edd_get_checkout_uri(); ?> " class="button"><?php _e('Checkout', 'edd'); ?> </a> </li>
/** * Validates the supplied discount sent via AJAX. * * @since 1.0 * @return void */ function edd_ajax_update_cart_item_quantity() { if (!empty($_POST['quantity']) && !empty($_POST['download_id'])) { $download_id = absint($_POST['download_id']); $quantity = absint($_POST['quantity']); $options = maybe_unserialize(stripslashes($_POST['options'])); edd_set_cart_item_quantity($download_id, absint($_POST['quantity']), $options); $total = edd_get_cart_total(); $return = array('download_id' => $download_id, 'quantity' => $quantity, 'taxes' => html_entity_decode(edd_cart_tax(), ENT_COMPAT, 'UTF-8'), 'subtotal' => html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8')); echo json_encode($return); } edd_die(); }
/** * Gets the total tax amount for the cart contents * * @since 1.2.3 * @param array $discounts Array of discounts to take into account (required for AJAX calls) * @return string Total tax amount */ function edd_get_cart_tax($discounts = false) { $subtotal = edd_get_cart_subtotal(false); $subtotal += edd_get_cart_fee_total(); $cart_tax = 0; if (edd_is_cart_taxed()) { if (edd_taxes_after_discounts()) { $subtotal -= edd_get_cart_discounted_amount($discounts); } $cart_tax = edd_calculate_tax($subtotal, false); } return apply_filters('edd_get_cart_tax', $cart_tax, $subtotal); }
/** * Apply the discounts to the cart * * @since 1.0 * * @access public * @return void */ public function apply_discounts($download_id, $options) { if (!function_exists('rcp_is_active')) { return; } $user_id = get_current_user_id(); if (!rcp_is_active($user_id)) { return; } $sub_id = rcp_get_subscription_id($user_id); if (!$sub_id) { $this->clear_cart_discounts(); return; } // Check for member discounts $discounts = get_posts(array('post_type' => 'edd_rcp_discount', 'posts_per_page' => '1', 'fields' => 'ids', 'meta_query' => array('relation' => 'AND', array('key' => '_edd_rcp_discount_subscription', 'value' => $sub_id)))); if (!$discounts) { $this->clear_cart_discounts(); return; } // Get cart details $cart_amount = edd_get_cart_subtotal(); $cart_details = edd_get_cart_content_details(); if (empty($cart_details)) { $this->clear_cart_discounts(); return; } // Subtract exclusions from the cart amount before calculating the discount below. foreach ($cart_details as $key => $download) { // Check for product-level exclusion if (get_post_meta($download['id'], 'rcp_member_discount_exclude')) { $cart_amount -= $download['item_price']; continue; } // Check for download category exclusions $terms = wp_get_object_terms($download['id'], 'download_category'); if (!$terms) { continue; } $term_discounted = false; foreach ($terms as $term) { if (!$term_discounted && get_term_meta($term->term_id, 'rcp_member_discount_exclude')) { $cart_amount -= $download['item_price']; $term_discounted = true; continue; } } } // If the cart amount is 0 after subtracting exclusions, no member discount is applied. if ('0' == $cart_amount) { $this->clear_cart_discounts(); return; } foreach ($discounts as $discount) { $percent = get_post_meta($discount, '_edd_rcp_discount_amount', true); $amount = $cart_amount * ($percent / 100) * -1; EDD()->fees->add_fee(array('amount' => $amount, 'label' => get_the_title($discount), 'id' => 'rcp_member_discount')); EDD()->session->set('rcp_member_discount_id', $discount); } }
} add_filter('edd_cart_item_price', 'edd_plans_filter_cart_price', 11, 4); function edd_plans_change_purchase_label($defaults) { global $edd_options; $post = get_post(); $payment_id = isset($_GET['payment_id']) ? absint($_GET['payment_id']) : (isset($defaults['payment_id']) ? $defaults['payment_id'] : 0); if ((strstr($post->post_content, '[purchase_history]') || strstr($post->post_content, '[downloads_history]')) && $payment_id > 0) { $licenses = edd_software_licensing()->get_licenses_of_purchase($payment_id); foreach ($licenses as $license) { $license_download_id = edd_software_licensing()->get_download_id($license->ID); if (absint($defaults['download_id']) == $license_download_id && 'expired' == edd_software_licensing()->get_license_status($license->ID)) { $defaults['text'] = __('Renew', 'edd_plans'); } } } return $defaults; } add_filter('edd_purchase_link_args', 'edd_plans_change_purchase_label', 11, 1); /** * Displays the renewal discount row on the cart * * @since 3.0.2 * @return void */ function edd_plans_sl_cart_items_renewal_row()
/** * 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)); }
/** * Validates the supplied discount sent via AJAX. * * @since 1.0 * @return void */ function edd_ajax_update_cart_item_quantity() { if (!empty($_POST['quantity']) && !empty($_POST['download_id'])) { $download_id = absint($_POST['download_id']); $quantity = absint($_POST['quantity']); $options = json_decode(stripslashes($_POST['options']), true); edd_set_cart_item_quantity($download_id, absint($_POST['quantity']), $options); $total = edd_get_cart_total(); $return = array('download_id' => $download_id, 'quantity' => $quantity, 'taxes' => html_entity_decode(edd_cart_tax(), ENT_COMPAT, 'UTF-8'), 'subtotal' => html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8')); // Allow for custom cart item quantity handling $return = apply_filters('edd_ajax_cart_item_quantity_response', $return); echo json_encode($return); } edd_die(); }
/** * Is Cart Minimum Met * * Checks to see if the minimum purchase amount has been met * * @since 1.1.7 * @param int $code_id Discount ID * @return bool $return */ function edd_discount_is_min_met($code_id = null) { $discount = edd_get_discount($code_id); $return = false; if ($discount) { $min = edd_get_discount_min_price($code_id); $cart_amount = edd_get_cart_subtotal(); if ((double) $cart_amount >= (double) $min) { // Minimum has been met $return = true; } else { edd_set_error('edd-discount-error', sprintf(__('Minimum order of %s not met.', 'edd'), edd_currency_filter(edd_format_amount($min)))); } } return apply_filters('edd_is_discount_min_met', $return, $code_id); }
/** * Determines what the currently selected gateway is * * If the cart amount is zero, no option is shown and the cart uses the manual * gateway to emulate a no-gateway-setup for a free download * * @access public * @since 1.3.2 * @return string $enabled_gateway The slug of the gateway */ function edd_get_chosen_gateway() { $gateways = edd_get_enabled_payment_gateways(); $chosen = isset($_REQUEST['payment-mode']) ? $_REQUEST['payment-mode'] : false; if (false !== $chosen) { $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); } if (!empty($chosen)) { $enabled_gateway = urldecode($chosen); } else { if (count($gateways) >= 1 && !$chosen) { foreach ($gateways as $gateway_id => $gateway) { $enabled_gateway = $gateway_id; if (edd_get_cart_subtotal() <= 0) { $enabled_gateway = 'manual'; // This allows a free download by filling in the info } } } else { if (edd_get_cart_subtotal() <= 0) { $enabled_gateway = 'manual'; } else { $enabled_gateway = edd_get_default_gateway(); } } } return apply_filters('edd_chosen_gateway', $enabled_gateway); }
/** * Get Cart Amount * * @since 1.0 * @deprecated 1.9 * @param bool $add_taxes Whether to apply taxes (if enabled) (default: true) * @param bool $local_override Force the local opt-in param - used for when not reading $_POST (default: false) * @return float Total amount */ function edd_get_cart_amount($add_taxes = true, $local_override = false) { $backtrace = debug_backtrace(); _edd_deprecated_function(__FUNCTION__, '1.9', 'edd_get_cart_subtotal() or edd_get_cart_total()', $backtrace); $amount = edd_get_cart_subtotal(); if (!empty($_POST['edd-discount']) || edd_get_cart_discounts() !== false) { // Retrieve the discount stored in cookies $discounts = edd_get_cart_discounts(); // Check for a posted discount $posted_discount = isset($_POST['edd-discount']) ? trim($_POST['edd-discount']) : ''; if ($posted_discount && !in_array($posted_discount, $discounts)) { // This discount hasn't been applied, so apply it $amount = edd_get_discounted_amount($posted_discount, $amount); } if (!empty($discounts)) { // Apply the discounted amount from discounts already applied $amount -= edd_get_cart_discounted_amount(); } } if (edd_use_taxes() && edd_is_cart_taxed() && $add_taxes) { $tax = edd_get_cart_tax(); $amount += $tax; } if ($amount < 0) { $amount = 0.0; } return apply_filters('edd_get_cart_amount', $amount, $add_taxes, $local_override); }
/** * Get Total Cart Amount * * Returns amount after taxes and discounts * * @since 1.4.1 * @global $edd_options Array of all the EDD Options * @param bool $discounts Array of discounts to apply (needed during AJAX calls) * @return float Cart amount */ function edd_get_cart_total($discounts = false) { global $edd_options; $subtotal = edd_get_cart_subtotal(); $cart_tax = edd_get_cart_tax(); $fees = edd_get_cart_fee_total(); $total = $subtotal + $cart_tax + $fees; if ($total < 0) { $total = 0.0; } return (double) apply_filters('edd_get_cart_total', $total); }
/** * Shows the final purchase total at the bottom of the checkout page * * @since 1.5 * @return void */ function edd_checkout_final_total() { ?> <p id="edd_final_total_wrap"> <strong><?php _e('Purchase Total:', 'edd'); ?> </strong> <span class="edd_cart_amount" data-subtotal="<?php echo edd_get_cart_subtotal(); ?> " data-total="<?php echo edd_get_cart_subtotal(); ?> "><?php edd_cart_total(); ?> </span> </p> <?php }
/** * 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); }
/** * Calculate Maximum Possible discount available * * Handles to calculate maximum possible discount * * @package Easy Digital Downloads - Points and Rewards * @since 1.0.0 **/ public function edd_points_get_discount_for_redeeming_points() { global $edd_options; //get users points $available_user_disc = $this->edd_points_get_userpoints_value(); //get cart subtotal $cartsubtotal = edd_get_cart_subtotal() - edd_get_cart_discounted_amount(); //check price is include tas or not if (edd_prices_include_tax() == 'yes') { $cartsubtotal = $cartsubtotal - edd_get_cart_tax(); } //check user has points or not if (empty($available_user_disc)) { return 0; } //get cart content $cartdata = edd_get_cart_contents(); $discount_applied = 0; // calculate the discount to be applied by iterating through each item in the cart and calculating the individual // maximum discount available foreach ($cartdata as $item_key => $item) { //max discount $max_discount = $this->edd_points_get_max_points_discount_for_download($item['id']); //check item of options set then consider that if (isset($item['options'])) { $itemoptions = $item['options']; } elseif (isset($item['item_number']['options'])) { $itemoptions = $item['item_number']['options']; } else { $itemoptions = array(); } //get download price $downloadprice = edd_get_cart_item_price($item['id'], $itemoptions); if (is_numeric($max_discount)) { // adjust the max discount by the quantity being ordered $max_discount *= $item['quantity']; // if the discount available is greater than the max discount, apply the max discount $discount = $available_user_disc <= $max_discount ? $available_user_disc : $max_discount; } else { //when maximum discount is not set for product then allow maximum total cost of product as a discount $max_price_discount = $downloadprice * $item['quantity']; // if the discount available is greater than the max discount, apply the max discount $discount = $available_user_disc <= $max_price_discount ? $available_user_disc : $max_price_discount; } // add the discount to the amount to be applied $discount_applied += $discount; // reduce the remaining discount available to be applied $available_user_disc -= $discount; } //end for loop // if the available discount is greater than the order total, make the discount equal to the order total less any other discounts $discount_applied = max(0, min($discount_applied, $cartsubtotal)); //$discount_applied = max( 0, $discount_applied ); // limit the discount available by the global maximum discount if set $max_discount = $edd_options['edd_points_cart_max_discount']; if ($max_discount && $max_discount < $discount_applied) { $discount_applied = $max_discount; } return $discount_applied; }
<?php } ?> <tr class="edd_cart_footer_row"> <?php do_action('edd_checkout_table_footer_first'); ?> <th colspan="<?php echo edd_checkout_cart_columns(); ?> " class="edd_cart_total"><?php _e('Total', 'easy-digital-downloads'); ?> : <span class="edd_cart_amount" data-subtotal="<?php echo edd_get_cart_subtotal(); ?> " data-total="<?php echo edd_get_cart_total(); ?> "><?php edd_cart_total(); ?> </span></th> <?php do_action('edd_checkout_table_footer_last'); ?> </tr> </tfoot> </table>