wc_empty_cart not working as expected
-
So I noticed that after a successful order, the cart contents were not being cleared.
I did some debugging and saw that if I manually overwrote the checkout/thankyou.php page, and var_dumped
WC()->cart
, the cart_contents is empty.But if I go to the cart and var_dump the same
WC()->cart
, the car_contents still contains the previous order details.If I call
wc_empty_cart
on the cart page above (with or without the persistent cart param) then thevar_dump(WC()->cart);
shows empty contents. As soon as I remove thewc_empty_cart()
call and refresh, last order’s products are still in there.Basically, unless I am using
WC()->cart->empty_cart();
to clear my cart contents manually on the thank you page or via a hook, the carts are not actually cleared and as soon as I leave the page withwc_empty_cart()
, the previous cart contents return.How would this be possible? Are there multiple versions of the cart instance?
Additional Info: Nothing is flagged on WC settings page, I genuinely have no hooks which aren’t front end output only, and there is nothing in any error logs (all transactions are working fine with no errors).
In fact, even If I have not had an order, and hard code
wc_empty_cart()
onto the top of my cart page, the cart is not emptied – this only happens if I hard codeWC()->cart->empty_cart();
.
- The topic ‘wc_empty_cart not working as expected’ is closed to new replies.