/** clears the cart/coupon data and re-calcs totals */ function clear_cache() { self::$cart_contents = array(); self::$applied_coupons = array(); unset( $_SESSION['cart'] ); unset( $_SESSION['coupons'] ); self::calculate_totals(); }
/** * Applies a coupon code * * @param string $coupon_code The code to apply * @return bool True if the coupon is applied, false if it does not exist or cannot be applied */ public static function add_discount($coupon_code) { if (!self::is_valid_coupon($coupon_code)) { return false; } // Check for other individual_use coupons before adding this coupon. foreach (self::get_coupons() as $code) { $current = JS_Coupons::get_coupon($code); if ($current['individual_use']) { jigoshop::add_error(__("There is already an 'individual use' coupon on the Cart. No other coupons can be added until it is removed.", 'jigoshop')); return false; } } $coupon = JS_Coupons::get_coupon($coupon_code); // Remove other coupons if this one is individual_use. if ($coupon['individual_use']) { if (!empty(self::$applied_coupons)) { jigoshop::add_error(__("This is an 'individual use' coupon. All other discount coupons have been removed.", 'jigoshop')); self::$applied_coupons = array(); } } // check if coupon is already applied and only add a new coupon if (!self::has_discount($coupon_code) && !empty($_POST['coupon_code'])) { self::$applied_coupons[] = $coupon_code; } // select free shipping method if ($coupon['free_shipping']) { if (Jigoshop_Base::get_options()->get('jigoshop_select_free_shipping_method') == 'yes') { jigoshop_session::instance()->chosen_shipping_method_id = 'free_shipping'; } } jigoshop_session::instance()->coupons = self::$applied_coupons; jigoshop::add_message(__('Discount coupon applied successfully.', 'jigoshop')); return true; }