Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gagimilicevic/5fa660b42436d9a4a40e77d61632fd2b to your computer and use it in GitHub Desktop.
Save gagimilicevic/5fa660b42436d9a4a40e77d61632fd2b to your computer and use it in GitHub Desktop.
Clear WooCommerce Cart (when not cart/checkout)
/**
* Clears WC Cart on Page Load
* (Only when not on cart/checkout page)
*/
add_action( 'wp_head', 'bryce_clear_cart' );
function bryce_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 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment