Skip to content

Instantly share code, notes, and snippets.

@Lonsdale201
Created February 13, 2024 21:34
Show Gist options
  • Select an option

  • Save Lonsdale201/24ede06b773d1e9a53c25c5354bf9442 to your computer and use it in GitHub Desktop.

Select an option

Save Lonsdale201/24ede06b773d1e9a53c25c5354bf9442 to your computer and use it in GitHub Desktop.
Learndash - programatically course enroll with wp registration
// 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