Hey all,
I'm having a problem trying to update a cookie array. What I'm trying to do is allow a user to delete a product out of their shopping cart, if necessary.
What the posted code is doing is, checking if the cookie id is equal to the id of the product they want to delete. Unfortunately, this code doesn't seem to want to update the cookie.
Here it is:
if ($delete) {
$j = 1;
for ($i = 1; $i <= count($_COOKIE['cookieUniqueID']); $i++) {
if ($_COOKIE['cookieUniqueID'][$i] == $_COOKIE['cookieUniqueID'][$delete]) {
//Do Nothing
} else {
setcookie($_COOKIE['cookieUniqueID'][$j], $_COOKIE['cookieUniqueID'][$i]);
$j++;
}
}
//$_COOKIE['cookieUniqueID'] = array_values($_COOKIE['cookieUniqueID']);
$j = 1;
for ($i = 1; $i <= count($_COOKIE['cookieQuantity']); $i++) {
if ($_COOKIE['cookieQuantity'][$i] == $_COOKIE['cookieQuantity'][$delete]) {
//Do Nothing
} else {
setcookie($_COOKIE['cookieQuantity'][$j], $_COOKIE['cookieQuantity'][$i]);
$j++;
}
}
//$_COOKIE['cookieQuantity'] = array_values($_COOKIE['cookieQuantity']);
}
I've also tried using unset, with a much simpler section of code 😉, but all that does is delete it when the page refreshes, but if you click on the "View Cart" button again, the product is back...
Anyway, any help in this would be greatly appreciated!