Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save actual-saurabh/16792a1e2ced3fa9d0994efbe59fbfc7 to your computer and use it in GitHub Desktop.

Select an option

Save actual-saurabh/16792a1e2ced3fa9d0994efbe59fbfc7 to your computer and use it in GitHub Desktop.
Prerequisite Course Enrollment
<?php // Do not copy this line
// Copy from under this line and paste into your child theme's functions.php
add_action( 'llms_user_enrolled_in_course', 'llms_enroll_in_prerequisite_course', 10, 2 );
function llms_enroll_in_prerequisite_course( $student_id, $course_id ){
/*
* the prerequiste course's id.
* You can get this by editing the course and getting the value of the post parameter of the screen's url
* https://yoursite.com/wp-admin/post.php?post=123&action=edit
*/
$prerequisite_course_id = 456;
// prevent an endless enrollment loop
if( (int) $course_id === (int) $prerequisite_course_id ){
return;
}
// enroll student into the addon course
llms_enroll_student( $student_id, $prerequisite_course_id );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment