woocommerce shows cart is empty in firefox,after adding the products to cart

woocommerce shows cart is empty when products are added,in firefox browser after redirecting to cart page. But works well in other browsers like Internet explorer and chrome. And, displays the number of items in the cart in all browsers,before redirecting to the cart page.

global $woocommerce;

$data=explode(',',$_POST['productids']);
try
{
for($i=0;$i<sizeof($data);$i++)
{
    if($data[$i]>0)
    {           
    WC()->cart->add_to_cart($data[$i],1);
    }
}
$my_cart_count = WC()->cart->get_cart_contents_count();
echo $my_cart_count;

}catch(Exception $e){echo $e;}

 echo '<script type="text/javascript">window.location="'.WC()->cart->get_cart_url().'";</script>';

And further, if I login and do the same process, everything works correctly.

Related posts

2 comments

  1. I had similar problem the cart was working in chrome and firefox but not in maxthon browser.. so it was quiet evident it was a browser issue not the script.. so I struggled and finally found that cookies were disabled in maxthon browser and when I enabled it , the cart started working properly..

    so you can try the same in your case for firefox..

    you can do following steps to enable cookies for firefox..

    • Select firefox Drop-down menu
    • Select Preferences
    • select Privacy
    • Set “Firefox will:” to Use custom settings for history.
    • Check “Accept cookies from sites” to enable cookies.
    • click Ok…

Comments are closed.