LMS & eLearning

How to Auto-Enroll Group Members Into Group Courses in LearnDash

The three automatic enrollment behaviours around LearnDash groups: group courses, the Group Courses Auto-enroll metabox that pulls course buyers into a group, and Managed Groups Auto-enrollment for leaders.

How to Auto-Enroll Group Members Into Group Courses in LearnDash

"Auto-enroll" means three different things around LearnDash groups, and support threads often mix them up. Group members automatically have access to group courses; that is the basic model. A group can also be set to pull in anyone who enrolls in one of its courses by other means, which is a separate metabox. And group leaders can be enrolled automatically into the groups they manage, which is a global setting. This guide covers each as LearnDash 4.18.0.1 implements it, so you can pick the one that matches what you actually want.

1. Group members get group courses

This needs no setting. When a user is added to a group, access to every course attached to that group follows, because course access checks include the courses of the user's groups. Attach a course to the group afterwards and existing members gain it too. There is no per-user enrollment record for group access, only the group membership meta, which is why the user profile shows those courses with a "Group Access" label rather than an enrollment date of their own. Setting this up is covered in creating groups and enrolling users.

The one subtlety is that group access is evaluated at request time. Remove the user from the group and the courses disappear immediately; remove a course from the group and members lose it, although their progress records remain.

2. Course enrollment pulls users into a group

This is the reverse direction and the one the metabox is for. Edit a group and find the Group Courses Auto-enroll box. It has a checkbox labelled "Enable automatic group enrollment when a user enrolls into any associated group course", and beneath it a selector listing the group's courses. The two work as alternatives:

  • With the checkbox on, stored as the group post meta ld_auto_enroll_group_courses set to yes, enrolling in any course attached to the group adds the user to the group.
  • With the checkbox off, only the courses ticked in the selector trigger it. Those IDs are stored in ld_auto_enroll_group_course_ids, and the saved list is intersected with the group's current courses, so removing a course from the group also removes it from the trigger list.

The hook that does the work runs on learndash_update_course_access, the action fired whenever a user is given access to a course. It ignores removals, loads the groups the course belongs to, checks each group's setting, and calls ld_update_group_access() for a match. Before adding the user it passes through the filter learndash_group_course_auto_enroll with the group ID and course ID, so a developer can veto it for particular combinations.

Because it listens to course access updates, it fires for every enrollment route: manual enrollment by an admin, a LearnDash purchase, a WooCommerce or membership plugin integration that calls the LearnDash access functions, and code that calls ld_update_course_access(). It does not fire for access the user already had through another group, since that path does not update course access.

What this is useful for

The typical use is a free or paid course that doubles as the entry point to a cohort. Sell the course individually, set the group to auto-enroll on that course, and every buyer lands in the group, where a group leader can see them, email them, and they receive the group's other courses. It also suits migrations: attach legacy courses to a new group with the checkbox on, and learners are added to the group as they next enroll.

What it is not: it does not enrol existing course users retroactively. Only enrollments that happen after the setting is saved trigger it. For existing users, add them to the group through the group's Users box or by code.

Vetoing by code

<?php
/**
 * Do not auto-enroll into group 42 when the trigger course is the free taster (course 77).
 */
add_filter(
    'learndash_group_course_auto_enroll',
    function ( $enroll, $group_id, $course_id ) {
        if ( 42 === (int) $group_id && 77 === (int) $course_id ) {
            return false;
        }

        return $enroll;
    },
    10,
    3
);

3. Leaders enrolled into the groups they manage

Under LearnDash LMS, Groups, Settings, the Group Leader User section has a switch labelled Managed Groups Auto-enrollment, stored as groups_autoenroll_managed. When it is on, the function that lists a leader's groups returns the groups they administer, so leaders are treated as members of their managed groups and get access to the group courses without being added as users. The same section has Courses Auto-enrollment, which gives leaders access to every course on the site, and a bypass for course limits. These are about leaders, not learners, and are explained with the rest of the leader permissions in letting group leaders manage users, courses and groups.

Administrators have their own equivalent under General settings, Admin User, where Courses Auto-enrollment is on by default. That is why an administrator always sees every course as enrolled while testing, and why testing enrollment flows needs a non-admin account.

Checking which one is in play

When a learner has a course you did not expect, work through the list in order: are they in a group that has the course, directly or through a parent group when the hierarchy is enabled; did they enrol in a trigger course of a group with auto-enroll on; are they a leader with managed group enrollment or course auto-enrollment; are they an administrator. The user's profile screen shows groups and courses side by side, and the course rows say whether access comes through a group.

The enrollment function the metabox calls is documented in enrolling into groups by code, the actions that fire when a user joins or leaves a group are in the group hooks reference, and parent and child group behaviour is in hierarchical groups explained.

When to get help

These settings cover the common cases. Rules such as "put the buyer in the group that matches their company email domain" or "move learners between groups when they complete a course" need a few lines of code on the hooks above, which is routine for our LearnDash services team and the LearnDash development work around it; a LearnDash developer can also script the one-off enrolment of existing users that the metabox does not do.

Frequently asked questions

Does Group Courses Auto-enroll add existing course students to the group?

No. It only reacts to enrollments that happen after it is enabled. Add existing students to the group manually or with a script.

Does a WooCommerce purchase trigger group auto-enroll?

Yes, provided the integration grants course access through LearnDash's access functions, which the official WooCommerce add-on does. The trigger listens to the course access update action, not to the purchase itself.

Can I auto-enroll into a group based on a course that is not attached to it?

Not with the metabox; it only offers the group's own courses. Use the group hooks or the course access action with your own code for that.

Why do group leaders see the group courses without being enrolled?

Because Managed Groups Auto-enrollment is on in the Group Leader User settings. Turn it off if leaders should only see courses they are enrolled in.

Add WorldWin Coder to your preferred sources

Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.

· Developers and project managers

Articles written and reviewed by the developers and project managers at WorldWin Coder, who build and maintain websites, web applications and mobile apps on WordPress, Moodle, PHP, Laravel, CodeIgniter and Flutter.

Keep reading

Have something to build, fix or move?

Tell us where you are. A developer reads every inquiry, and you get next steps and a free quote within one business day.