Browse: Home / Snippets /

Add Custom User Role to User when they complete a specific course.

Contents


Snippet #

Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.

add_action( 'learndash_course_completed', function( $data ) {
    $course_id = 1234; // course_id for action.
    $user_role = 'course_completed'; // user role to add to user.

    $userID = $data['user']->ID;

    if ( $data['course']->ID == $course_id ) {
        $User = new WP( $userID );
        $User->add_role( $user_role );
    }
}, 20 );