WC()->cart->add_to_cart(8, 1);
I am using the above code to add dynamic products in the cart. It’s working fine when I am logged in but it fails to add products while I am not logged in. How to fix this?
WC()->cart->add_to_cart(8, 1);
I am using the above code to add dynamic products in the cart. It’s working fine when I am logged in but it fails to add products while I am not logged in. How to fix this?
Comments are closed.
Answering 2 years later in case anyone has a similar problem.
I solved this by adding first adding the item to the cart, and then setting the woocommerce session cookie: