Skip to content

Instantly share code, notes, and snippets.

@octalmage
Created October 26, 2015 07:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save octalmage/563b885ef8df1a017a23 to your computer and use it in GitHub Desktop.
Save octalmage/563b885ef8df1a017a23 to your computer and use it in GitHub Desktop.
Force clear WooCommerce cart for WordPress user.
<?php
add_action( 'init', 'force_clear_woocommerce_cart' );
function force_clear_woocommerce_cart()
{
$user_ID = get_current_user_id();
if ($user_ID === 68364)
{
error_log("Clearing cart");
global $woocommerce;
$woocommerce->cart->empty_cart();
}
}
@michaelmcguk
Copy link

I had to move the add_action below the function for this to work for me. Thank you : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment