Last active
June 20, 2023 19:30
-
-
Save yanknudtskov/ef6b349cf9e8bee436358f17e1ee7909 to your computer and use it in GitHub Desktop.
WooCommerce Subscriptions check if the current user has an active subscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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