How to remove WooCommerce persistent cart data from database?
Asked Answered
S

1

-1

From answers found in stack overflow, I noticed that WooCommerce cart data stored in wp_woocommerce_sessions database table, but after deleting data from this table and also deleting related cookies and session store in the browser, all items are still remaining in the cart.

How to remove WooCommerce persistent cart data from database?

Spermatium answered 29/8, 2023 at 18:55 Comment(9)
If the table is empty, close the browser to clear the session most likely.Monazite
It didn't help, but thank you;-)Dues
What about a full reboot? If that doesn't work, then check every table, maybe there is another table it stores things like this.Monazite
It's too complicated way. Better to know what tables exactly store this dataDues
And another strange thing — why question is dislikedDues
I didn't do it, but if you read the terms of service, you NEED to post the code, the table layouts, and all that, otherwise its just a guessing game. It creates brevity.Monazite
It's disliked and could be closed as duplicated, as your title was not reflecting what you really wanted to ask, and your content was a bit unclear.Bridoon
What have you tried so far? Where are you stuck? Manually deleting rows from a table sounds strange, as no user of your website would be able to do thisGeibel
@NicoHaase In WooCommerce users can empty themselves the cart by removing each item added previously. So this is just for the OP, for sure, his intention is not explained.Bridoon
B
3

For registered users, persistent cart data is stored as user metadata in wp_usermeta database table. You need also to remove that persistent cart user metadata from the user ID:

update_user_meta( $user_id, '_woocommerce_persistent_cart_1', '' );

So the meta_key to target in wp_usermeta table is _woocommerce_persistent_cart_1 for the related User ID.

The best way to remove the persistent cart data programmatically is using the WC_Cart method empty_cart(), that will empty cart, removing that persistent cart data at the same time:

if ( ! WC()->cart->is_empty() ) {
    WC()->cart->empty_cart();
}

Related: WooCommerce cookies and sessions - Get the current products in cart

Bridoon answered 30/8, 2023 at 0:27 Comment(2)
Yes, this helped=) Thanks a lot! So to get an empty cart for registered user one should delete both wp_usermeta table and related wp_woocommerce_sessions tableDues
I marked answer as accepted. Forgot to do thisDues

© 2022 - 2025 — McMap. All rights reserved.