When customer click cancel subscription, they still can logged in the my account section, but I want to let user cannot access anything on my account section. From this point, I would like to make the function on "if the user cancels payment, it also delete the account too" to make them cannot access, so I try to investigate and write the code below.
add_action( 'woocommerce_order_status_cancelled',
'custom_woocommerce_auto_delete_user' );
function custom_woocommerce_auto_delete_user( $order_id ) {
global $woocommerce;
$order = new WC_Order( $order_id );
$order_status = $order->get_status();
if ( !$order_id )
return false;
if ('cancelled' == $order_status) {
$current_user = wp_get_current_user();
wp_delete_user( $current_user->ID,true );
return true;
}
return false;
}
However, I'm just the beginner of woocommerce and I don't know which solution is the best for this issue. I'm so glad for anyone that come to response to me :)