Skip to content

Instantly share code, notes, and snippets.

@yanknudtskov
Last active June 20, 2023 19:30
Show Gist options
  • Save yanknudtskov/ef6b349cf9e8bee436358f17e1ee7909 to your computer and use it in GitHub Desktop.
Save yanknudtskov/ef6b349cf9e8bee436358f17e1ee7909 to your computer and use it in GitHub Desktop.
WooCommerce Subscriptions check if the current user has an active subscription
<?php
function yanco_has_active_subscription( $user_id = '' ) {
if( function_exists( 'wcs_user_has_subscription' ) ) {
// 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' );
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment