My company's site adds coupons with this updatecart function (below), but there is no way to remove a coupon without going into the backend to delete it. I want to add that option, but I'm not sure where to start. I'm hoping it might be something simple like just setting coupon to "" or something like that? And then I assume I'll have to go the html and add an actual 'clear' button, but I believe I can handle that part on my own. Any advice on how I might be able to clear a previously added coupon would be greatly appreciated!
function updatecart ($remove, $quantity) {
global $DB_site, $dbprefix, $settings, $lang, $cart, $ae;
if (is_array($remove)) {
foreach ($remove as $k => $v) $cart->removeitem(intval($k));
}
if (is_array($quantity)) {
foreach ($quantity as $k => $v) {
$temp = explode(":", $k);
$errors = $cart->revalidateitem($temp['0'], $v, false);
if (!$errors) $cart->updatequantity($temp['0'], intval($v));
}
}
if (isset($_POST['coupon']) && $_POST['coupon'] != "") {
$results = $DB_site->query_first("SELECT * FROM `".$dbprefix."coupons` d WHERE
d.`status`='1' AND (d.`used`<d.`max` OR d.`max`='0') AND
d.`vstart`<='".stamp()."' AND d.`vend`>='".stamp()."' AND
d.`omin`<='".p($cart->subtotal(), false)."' AND
(d.`omax`>='".p($cart->subtotal(), false)."' OR d.`omax`='".p(0, false)."') AND
d.`code`='".desql($_POST['coupon'])."'".restrict('d')
);
if ($results['id'] != "") {
$cart->coupon = $_POST['coupon'];
$ae->new_alert($lang['cart_view']['coupon'].$cart->coupon.$lang['cart_view']['coupadded']);
} else {
$ae->new_error($lang['cart_view']['coupon'].$_POST['coupon'].$lang['cart_view']['coupfailed']);
}
}
}