Can I auto enroll users into LearnDash course after passing another course with certain result?

1.2k views Asked by At

I am looking for a way to unlock a LearnDash course based on the user's results from all quizzes in a prerequisite course.

I have bought the LearnDash Adaptive Learning Pro plugin supposed to do the job, but it is not working with the latest version of LearnDash 3.2.3.5 and I am near the deadline of my project.

So I started to look how to create a custom function that can get users overall score and enroll him into the next course which is set to Closed.

I found an old thread auto-enrolling WP Roles in a Learndash course that was not working but managed to fix by just replacing $users with $blogusers.

// Enrolling user role into courses
$blogusers = get_users( [ 'role__in' => [ 'subscriber'] ] );
foreach ( $blogusers as $user ) {
    ld_update_course_access( $user->ID, 5883, false );
    ld_update_course_access( $user->ID, 7521, false );
    ld_update_course_access( $user->ID, 6108, false );
}

Now, I need a function that gets the user's "cumulative score" for a course (which is average for all quizzes in a course) and compare if it's greater than "70" for e.g to enroll the users into other courses.

Is it possible?

Thanks

1

There are 1 answers

0
Mariyan Hristov On

Finally, I managed to figure this thing out for now. It's a bit lame with the shortcode but is working perfect for me. I am posting the solution here for anyone that is searching the internet for similar case.

$user = get_current_user_id();
$score_module01 = do_shortcode( "[courseinfo show=\"cumulative_percentage\" course_id=\"1383\"]" );
// Set needed score for Module 01
$needed_score = 70;

if ( "$score_module01" >= "$needed_score" )  {

// Enroll user into courses after Module 01
    ld_update_course_access( $user, 5883, false );
    ld_update_course_access( $user, 7521, false );
}