Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save actual-saurabh/8f8f2182e67ac9bcf266b65b37d29f95 to your computer and use it in GitHub Desktop.
Save actual-saurabh/8f8f2182e67ac9bcf266b65b37d29f95 to your computer and use it in GitHub Desktop.
Enroll into a membership on completion of a specific welcome course
<?php // Do not copy this line
// Copy from under this line and paste into your child theme's functions.php
add_action( 'lifterlms_course_completed', 'llms_enroll_in_restrictive_membership', 10, 2 );
function llms_completed_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;
/*
* the membership's id.
* You can get this by editing the membership and getting the value of the post parameter of the screen's url
* https://yoursite.com/wp-admin/post.php?post=456&action=edit
*/
$restrictive_membership_id = 456;
// prevent an inception like scenario and run the remaining code only when student completes welcome course
if( (int) $course_id === (int) $welcome_course_id ){
return;
}
// enroll student into the welcome course
llms_enroll_student( $student_id, $restrictive_membership_id );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment