I am wondering how you can clear the contents of your cart on page load using woocommerce.
I came accross how to add a clear cart button using by adding this in to f
None of the codes above works on my website. I test it in the latest WordPress version 5.4.1 and the below function works perfectly!
/**
Clears WC Cart on Page Load
(Only when not on cart/checkout page)
*/
add_action( 'wp_head', 'wc_clear_cart' );
function wc_clear_cart() {
if ( wc_get_page_id( 'cart' ) == get_the_ID() || wc_get_page_id( 'checkout' ) == get_the_ID() ) {
return;
}
WC()->cart->empty_cart( true );
}