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?
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