WC()->cart->add_to_cart. Unable to add 2 items.
-
I’m adding a downloadable virtual product to the cart via WC()->cart->add_to_cart(…) . Adding the first product works fine and the /cart/ page shows the item no problem.
The issue is when I add another different downloadable virtual product using WC()->cart->add_to_cart(…). I get the unique item_cart_key back with no errors and everything seems fine except it does not show up on the /cart/ page.
Did a lot of debugging. I found that when I call WC()->cart->get_cart() right after adding the 2nd item, it gets the cart from get_cart_from_session() and it triggers the filter woocommerce_cart_contents_changed . The 2nd item is not in the cart_contents. Always reverts back to the first item.
I hooked into woocommerce_pre_remove_cart_item_from_session just to see if both items show up but only the first one. The second item gets lost.
My question is calling WC()->cart->get_cart() right after WC()->cart->add_to_cart(…), shouldn’t it get the cart info from class-wc-cart.php instead of class-wc-cart-session.php? Is there a way to force the 2nd item into the session’s cart if that’s the case?
Any help to point me in the right direction is appreciated. Thanks Dana
- The topic ‘WC()->cart->add_to_cart. Unable to add 2 items.’ is closed to new replies.