How To Detect User Subscriptions WooCommerce?
Learn how to retrieve user woocommerce subscription data and even see if they have any active subscription.
I was implementing a third-party chat system, but I only wanted it to work with subscription users. So I needed to find the function to make this happen. Luckily this was very simple. If you need to retrieve user subscription data you can use this function to make it happen.
function has_active_subscription( $user_id='' ) {
// When a $user_id is not specified, get the current user Id
if( '' == $user_id && is_user_logged_in() )
$user_id = get_current_user_id();
// User not logged in we return false
if( $user_id == 0 )
return false;
return wcs_user_has_subscription( $user_id, '', 'active' );
}
You can also use a function like this
wcs_get_users_subscriptions($user_id);