Created
February 13, 2024 21:34
-
-
Save Lonsdale201/24ede06b773d1e9a53c25c5354bf9442 to your computer and use it in GitHub Desktop.
Learndash - programatically course enroll with wp registration
This file contains hidden or 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
| // copy this code in the child theme functions.php or a specific code plugin like FluentSnippets | |
| add_action( 'user_register', 'auto_enroll_user_to_course', 10, 1 ); | |
| function auto_enroll_user_to_course( $user_id ) { | |
| if ( ! is_wp_error( $user_id ) ) { | |
| $course_ids = array( 131 ); // Course ID, or ID's user separate comme if you want to add multiple id. | |
| if ( !is_array( $course_ids ) ) { | |
| $course_ids = array( $course_ids ); | |
| } | |
| foreach ( $course_ids as $course_id ) { | |
| ld_update_course_access( $user_id, $course_id, false ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment