• Resolved sdwarwick

    (@sdwarwick)


    I re-direct people to a log in / register page made with your shortcodes when they try to access pages other than a landing page. Upon completion of the user registration, I want them to be automatically enrolled in a specific course, which is free and unlimited to those that are logged in.

    Once registered or logged in, I want to direct them to the beginning of the course.

    I need a function /action that enables me to programmatically do a free enrollment for a specific course that I can insert after registration is completed. Regretfully I have not yet found anything documented. Can you suggest something?

    By the way, I am very impressed with the quality of the code base. In general it is not hard to figure out how to modify things – other than the course registration and payment code so far!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter sdwarwick

    (@sdwarwick)

    For Lifterlms!

    @sdwarwick,

    The function you’re looking for is llms_enroll_student(): https://github.com/gocodebox/lifterlms/blob/master/includes/functions/llms.functions.person.php#L72-L87

    I think the action you want to hook into is: https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.person.handler.php#L601

    We try really hard to keep our inline documentation current so if you’re looking for specific things that don’t show up on the docs portal, chances are it’s in the codebase somewhere.

    Hope that helps,

    Thread Starter sdwarwick

    (@sdwarwick)

    This is perfect!

    Thanks for the recommended hook as well.

    Thread Starter sdwarwick

    (@sdwarwick)

    For folks interested in this kind of behavior, here is what I ended up doing. I add a “Custom Field” to courses that I want auto enrolled with the key “autoEnroll” and the value “true”

    when someone registers, all courses with that field are auto-enrolled.

    the following is added to functions.php :

    // auto-enroll in specific course
    add_action('lifterlms_user_registered', 'addUserToCourse', 10, 1);
    function addUserToCourse($personID)
    {
        $postList = array('post_type'=>'course','meta_key'=>'autoEnroll','meta_value' =>'true');
        foreach ($postList as $post) {
            llms_enroll_student( $personID, $post->ID, 'registered' ) ;
        }
    }

    Note that I do not check to see if the person is already enrolled on the assumption that newly registered people are not enrolled in anything by default.

    • This reply was modified 9 years, 4 months ago by sdwarwick.
    • This reply was modified 9 years, 4 months ago by sdwarwick.
    Thread Starter sdwarwick

    (@sdwarwick)

    try that again:

    // auto-enroll in specific course called Improve IT
    add_action('lifterlms_user_registered', 'addUserToCourse', 10, 1);
    function addUserToCourse($personID)
    {
        $postTypes = array('post_type'=>'course','meta_key'=>'autoEnroll','meta_value' =>'true');
        $postList = get_posts($postTypes);
        foreach ($postList as $post) {
            llms_enroll_student( $personID, $post->ID, 'registered' ) ;
        }
    };
    
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Need code to auto-enroll after registration’ is closed to new replies.