/** * Checks whether discounts are still valid when removing items from the cart * * If a discount requires a certain product, and that product is no longer in the cart, the discount is removed * * @since 1.5.2 * * @param int $cart_key */ function edd_maybe_remove_cart_discount($cart_key = 0) { $discounts = edd_get_cart_discounts(); if (!$discounts) { return; } foreach ($discounts as $discount) { if (!edd_is_discount_valid($discount)) { edd_unset_cart_discount($discount); } } }
/** * Removes a discount code from the cart via ajax * * @since 1.7 * @return void */ function edd_ajax_remove_discount() { if (isset($_POST['code'])) { edd_unset_cart_discount(urldecode($_POST['code'])); $total = edd_get_cart_total(); $return = array('total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8'), 'code' => $_POST['code'], 'discounts' => edd_get_cart_discounts(), 'html' => edd_get_cart_discounts_html()); echo json_encode($return); } edd_die(); }