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;

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


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: