I have trouble with I can add to cart is fine, but when I view the cart page. the item won’t show up unless I refresh the page. same problem with delete item in the cart.
Does it have anyway, it will auto refresh when action trigger?
There’s a cookie set on the page, thinking might be the issue.
Thank you so much for the help!
—– code ———-
<?php
if(get_query_var('remove') > 0){
$r = get_query_var('remove');
$d = get_query_var('d');
if (isset($_COOKIE['cart'])) {
$cart = json_decode(base64_decode($_COOKIE['cart']), true);
unset($cart[$r][$d]);
if(empty($cart[$r])){
unset($cart[$r]);
}
if(empty($cart)){
setcookie("cart", base64_encode(json_encode($cart)), time() - 3600, '/');
} else {
setcookie("cart", base64_encode(json_encode($cart)), time() + 2592000, '/');
}
header('Location: '.get_the_permalink());
die();
} else {
header('Location: '.get_the_permalink());
die();
}
}
]]>
If anyone has any suggestion please let me know.
Big Thanks!