uo_done_button_redirect_link
Filters the redirect link for the "Done" button after course completion.
add_filter( 'uo_done_button_redirect_link', $callback, 10, 1 );
Description
Filters the URL for the "Done" button on lesson completion. Allows modification of the redirect link based on user, course, or lesson context. Defaults to the course completion URL or course page. Useful for custom redirect logic after a user finishes a lesson.
Usage
add_filter( 'uo_done_button_redirect_link', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
add_filter( 'uo_done_button_redirect_link', function( $button_link, $user_ID, $course_id, $lesson_id ) {
// Example: If the user is not enrolled in the course, redirect them to the course login page instead of completion.
if ( ! learndash_is_user_enrolled( $user_ID, $course_id ) ) {
// You would likely have a custom page ID or URL for your course login.
// For demonstration, let's assume a general course archive URL.
$course_archive_url = get_post_type_archive_link( 'sfwd-courses' );
if ( $course_archive_url ) {
return $course_archive_url;
}
}
// Example: If this is a specific lesson that requires a special post-completion action,
// update the button link accordingly.
// Let's say lesson ID 123 has a special redirect.
if ( '123' === $lesson_id ) {
$button_link = home_url( '/special-completion-page/' );
}
// Return the modified or original button link.
return $button_link;
}, 10, 4 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/lesson-topic-auto-complete.php:866
// Set the button link to the course completion URL, if applicable. Otherwise, fallback to the course page.
$button_link = learndash_course_get_completion_url( $course_id );
}
// this isn't an ajax call.
if ( ! wp_doing_ajax() ) {
$button_link = apply_filters( 'uo_done_button_redirect_link', $button_link, $user_ID, $course_id, $lesson_id );
// display the button on the last step.
self::done_button( $button_link );
} else {
return $button_link;
}