Forked from arsalan13nov/LearnDash Redirect on Course Completion
Created
November 27, 2020 07:34
-
-
Save VanessaKing/71a24f473532fee1690811329e131a5e to your computer and use it in GitHub Desktop.
LearnDash Redirect on Course Completion
This file contains 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
// Adding Custom Redirection field in LD Courses | |
add_filter( 'learndash_post_args', 'add_topic_option' ); | |
function add_topic_option( $post_args ) { | |
// New Course field to add redirection link. | |
$redirect_on_completion = array( | |
'redirect_on_completion' => array( | |
'name' => __( 'Redirect on Completion', 'learndash' ), | |
'type' => 'text', | |
'initial_options' => '', | |
'help_text' => __( 'Add redirection on completion', 'learndash' ), | |
'default' => '', | |
'show_in_rest' => true, | |
)); | |
// Pass the new field in the topic fields array. | |
$post_args['sfwd-courses']['fields'] = array_merge( $redirect_on_completion, $post_args['sfwd-courses']['fields'] ); | |
return $post_args; | |
} | |
// Redirecting to custom link on course completion | |
add_action( 'learndash_course_completed', 'redirect_to_link' ); | |
function redirect_to_link( $data ) { | |
if( empty( $data ) ) | |
return false; | |
$course_id = $data['course']->ID; | |
$redirect_on_completion = learndash_get_setting( $course_id, 'redirect_on_completion', true ); | |
if( $redirect_on_completion != '' ) { | |
wp_redirect( $redirect_on_completion ); | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment