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.
There’s a cookie set in the code, which I not familiar with, thinking might be the issue.
I thought I move the to the top will fix some issue, but the cart won’t work. I got some unexpected end error on WP debug tool, so I tried to use PHP checker to see how many } I miss and add it back, and still not working.
Thank you so much for the help!
—–– More Info ———-
Wordpress version: 4.9.7 PHP server: 5.6 Theme development date: unknown (Twenty thirteen theme modify version, never update)
—–– 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();
}
}
?>
<?php get_header();?>
<?php if(isset($ok) && $ok == 1){?>
<p class='after_cart_text'>Thank you for the opportunity to quote your project! We will endeavour to respond within 24 hours.</p>
<?php } else { ?>
<?php if(isset($ok) && $ok == -1){?>
<div class="alert alert-danger" role="alert">Please check the the captcha form.</div>
<?php } ?>
<div class="baners_categories">
<?php
$rows = get_field('banery_categories', 'options');
if($rows){
shuffle( $rows );
$image = $rows[0]['picture_categories'];
?>
<img src="<?php echo $image; ?>" />
<?php
}
?>
</div>
</fieldset>
<fieldset>
<!-- Form Name -->
<p class="legend_pe"><legend>Product Information</legend></p>
<?php if(isset($_COOKIE['cart']) && !empty($_COOKIE['cart']) && $post->post_name == 'cart'){
$cart = json_decode(base64_decode($_COOKIE['cart']), true);
//var_dump($cart);
$i = 0;
if (is_array($cart)) {
foreach($cart as $k => $row){
foreach($row as $k2 => $item){
//var_dump($item);
?>
<!-- form section code I comment it out -->
<?php }?>
<?php }?>
<div class="col-sm-4" style="margin-bottom:15px;">
<p><strong>Your cart is currently empty.</strong></p>
</div>
<?php }?>
<?php }?>
<?php }?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Thank you so much for any helps or tips!
]]>header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
]]>