• Resolved rdanamcd

    (@rdanamcd)


    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter rdanamcd

    (@rdanamcd)

    I’m calling WC()->cart->get_cart() after a Formidable form submit. Looks like that’s causing the issue after further testing. It works correctly adding items to the cart using url parameters during a page load. This works for me. Thanks

    Hi @rdanamcd

    Thanks for reaching out!

    I’m glad you were able to find a solution to your issue here and thanks for sharing it with the community too! ??

    I will be marking this thread as resolved. Should you have further inquiries, kindly create a new topic here.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WC()->cart->add_to_cart. Unable to add 2 items.’ is closed to new replies.