-
-
Save barbareshet/2a61dcf44dcf6ffd486b9a3edcf8b022 to your computer and use it in GitHub Desktop.
Check if user has enrolled into any course at your LearnPress website.
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 to check if given user is enrolled into any course. | |
*/ | |
function wpac_check_enrolled_user($user_id){ | |
if (is_numeric($user_id)) { | |
//Global WordPress DB object | |
global $wpdb; | |
//User ID to check use get_current_user_id() if you want to fetch current logged-in user's ID | |
$user_id = intval($user_id); | |
//Table name of LearnPress user items | |
$table_name = $wpdb->prefix . 'learnpress_user_items'; | |
//Database Query to count the results | |
$check_enrollment = $wpdb->get_var( $wpdb->prepare( | |
"SELECT COUNT(*) FROM `$table_name` WHERE user_id = %d", | |
$user_id | |
) ); | |
if($check_enrollment > 0) { | |
retrurn true; | |
} else { | |
rerturn false; | |
} | |
} else { | |
rerturn false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment