Woocommerce Remove all Items from cart on New Session

I’m want to clear all items in cart when a new session is started. I’ve tried

add_action( 'init', 'clear_cart_on_it' );
function clear_cart_on_it() {
    global $woocommerce;
    $woocommerce->cart->empty_cart();
 }

It is throwing this error:

Fatal error: Call to a member function empty_cart() on null in /home/shuggapa/public_html/wp-content/plugins/candy-scoops/scoops.php on line 53

I have no idea why. Please how can I implement this.

Read more here: Woocommerce Remove all Items from cart on New Session

Leave a Reply

Your email address will not be published. Required fields are marked *