Last active
April 17, 2019 06:40
-
-
Save actual-saurabh/3ce88c1b1465224eeab16e884d5916ec to your computer and use it in GitHub Desktop.
Enroll all students into a welcome course when they enroll into any course in LifterLMS
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 // 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_welcome_course', 10, 2 ); | |
// Uncomment to enroll when user joins a membership | |
add_action( 'llms_user_added_to_membership_level', 'llms_enroll_in_welcome_course', 10, 2 ); | |
function llms_enroll_in_welcome_course( $student_id, $course_id ){ | |
/* | |
* the welcome 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 | |
*/ | |
$welcome_course_id = 123; | |
// prevent an inception like scenario and run the remaining code only when student enrolls in any other course | |
if( (int) $course_id === (int) $welcome_course_id ){ | |
return; | |
} | |
// enroll student into the welcome course | |
llms_enroll_student( $student_id, $welcome_course_id ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment