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.
Possible reasons :-
WordPress memory limit may be exceeded.
Edit your wp-config.php file and enter something like:
Put secret keys in your wp-config.php
WP Secret key generate
Please check this article Woocommerce: Solving the âCart is Emptyâ issue
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..