function edd_wallet_process_incentive() { if ($_REQUEST['gateway'] == 'wallet') { EDD()->session->set('wallet_has_incentives', '1'); } else { EDD()->session->set('wallet_has_incentives', null); } // Refresh the cart if (empty($_POST['billing_country'])) { $_POST['billing_country'] = edd_get_shop_country(); } ob_start(); edd_checkout_cart(); $cart = ob_get_clean(); $response = array('html' => $cart, 'tax_raw' => edd_get_cart_tax(), 'tax' => html_entity_decode(edd_cart_tax(false), ENT_COMPAT, 'UTF-8'), 'tax_rate_raw' => edd_get_tax_rate(), 'tax_rate' => html_entity_decode(edd_get_formatted_tax_rate(), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_cart_total(false), ENT_COMPAT, 'UTF-8'), 'total_raw' => edd_get_cart_total()); echo json_encode($response); edd_die(); }
/** * 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); }
/** * Recalculate cart taxes * * @since 1.6 * @return void */ function edd_ajax_recalculate_taxes() { if (!edd_get_cart_contents()) { return false; } if (empty($_POST['billing_country'])) { $_POST['billing_country'] = edd_get_shop_country(); } ob_start(); edd_checkout_cart(); $cart = ob_get_clean(); $response = array('html' => $cart, 'tax_raw' => edd_get_cart_tax(), 'tax' => html_entity_decode(edd_cart_tax(false), ENT_COMPAT, 'UTF-8'), 'tax_rate_raw' => edd_get_tax_rate(), 'tax_rate' => html_entity_decode(edd_get_formatted_tax_rate(), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_cart_total(false), ENT_COMPAT, 'UTF-8'), 'total_raw' => edd_get_cart_total()); echo json_encode($response); edd_die(); }
/** * 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; }