Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

michaelmcguk commented Oct 3, 2017

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