I use this code for Virtuemart:
$product_id_to_remove = 3;
$cart = json_decode($_SESSION['__vm']['vmcart']);
foreach($cart->cartProductsData as $k => $v){
if($v->virtuemart_product_id == $product_id_to_remove) unset($cart->cartProductsData[$k]);
}
$_SESSION['__vm']['vmcart'] = json_encode($cart);
but I get the fatal error: Cannot use object of type stdClass as array in ... line 4. If I add true at json_decode($_SESSION['__vm']['vmcart']) I get the warning: Invalid argument supplied for foreach().
How to resolve the problem?
p.s. I'm beginner in php and don't know json_ at all. The code is suggested by the link: stackoverflow.com/questions/28691203/how-to-remove-a-single-product-from-mod-virtuemart-cart