I came across this code for clearing a Woocommerce cart on certain page loads.
But, I wonder is there a way to clear the cart after it has been abandoned?
For triggering only on front page your function needs to look like this:
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
global $woocommerce;
if ( is_front_page() && isset( $_GET['empty-cart'] ) ) {
$woocommerce->cart->empty_cart();
}
}
function is_front_page() returns true only on front page of your wordpress site. Also, you might detect any other page with function is_page() where you can pass any page title, ID or slug
From this question: Set WooCommerce Cart Expiration
I’ve adjusted the code a little bit to switch to a 24 hour session. I’m not sure you want to be deleting every few minutes as that has the potential to be performance-heavy.