Created
September 21, 2018 21:38
-
-
Save arsalan13nov/38111e854cdfc9273019c6c650f09dc2 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; | |
} | |
} |
This is exactly what I'm looking for, but I wanted to know where to put the code? I added it to my child theme's functions file, but it doesn't seem to have added the redirection url field. Does it need to go into one of the plugin files? That would make it a pain during plugin updates, but well worth the extra step.
Also, where do I look for the new field? Is it going to be under the individual Course's settings…?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Redirect to where? How can I controle where it should redirect?