Skip to content

Instantly share code, notes, and snippets.

@wpacademy
Last active August 30, 2022 06:06
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wpacademy/ff5f779ea6825dfb127a7ddce7f6fdef to your computer and use it in GitHub Desktop.
Check if user has enrolled into any course at your LearnPress website.
<?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;
}
}
@kaifahmad111
Copy link

Can you help me to get the courses that the student has enrolled in, I need to populate the data in Student Dashboard using the enrolled course!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment