I have a recurring issue in my Woocommerce site which is that the Cart is not cleared after an order is placed in my site.
I want to add a code in my_theme/functions.php to make sure the cart is cleared. I managed to create this code (below).
Will this be enough to get what I need?
add_action('woocommerce_new_order','clear_the_cart');
function clear_the_cart()
{
global $woocommerce;
$woocommerce->cart->empty_cart();
}
Do I need to add a code to get the user ID and then clear the cart for that user?
If the cart is cleared for each user instead of for all users then, I guess I will need to get the current user id and then after execute the line of code to clear the cart for that user.
My question is whether I should clean the cart by user or globally?
I know how to grab the user id:
$user_ID = get_current_user_id();
....