Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

custom post to cart won’t update (cookie issue)

$
0
0

Replies: 0

Hi everyone
I’m working on one client site, the previous developer uses custom post type build like a product collection page, kind like woo commerce, but only can add to cart to request a quote to the company, no transaction on the cart application.

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();
	}
 } 

Viewing all articles
Browse latest Browse all 59525

Trending Articles