Woocommerce – Clear cart on user logout

I am using woocommerce in wordpress site.

I need to clear cart contents of a logged in user when that user logs out.

Read More

I am unable to find any options for the same in plugin settings.

Anyone let me know a way to achieve the same.

Related posts

1 comment

  1. Use wp_logout hook to empty the cart. Place the below code in your theme’s function.php or in your own plugin.

    function your_function() {
        if( function_exists('WC') ){
            WC()->cart->empty_cart();
        }
    }
    add_action('wp_logout', 'your_function');
    

    Edited: According to @helgatheviking ‘s solution

Comments are closed.