• Resolved Augusto Gentile

    (@agugentile)


    Hi, how can I redirect enrolled users to the lesson instead to the course page?

    I found this but could not implemented:

    https://gist.github.com/creativeartbd/45917fdda38ca6741cdb172dfb6e41e4

    /*On the Enrolled Course page, You can see all the enrolled courses, right? Now, if you click on the title of the course you will be redirected to the course page. Okay, but if you want to redirect the user to the first lesson of any course then what? Well, use this code: Go to wp-content/plugins/tutor/templates/dashboard/enrolled-courses.php at line number 39. Here you can see this code:*/ $custom_url = home_url($post->post_type.’/’.$post->post_name); /* After this line add this code: */ $lesson_url = tutor_utils()->get_course_first_lesson( get_the_ID() ); /*Now, Replace the $custom_url with $lesson_url so that when you click on the title it will directly go to the lesson instead of the course page.*/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello @agugentile,

    Thanks for reaching out to us.

    If that is indeed your requirement, I want to clarify that Tutor LMS does not currently have a built-in feature to achieve this. However, it can be implemented by adding some custom code to your theme’s functions.php file.
    Please note that this solution would require updating the code every time a new course is added, as the system dynamically manages course redirection to the course details page.
    You can redirect users to the lessons page when they click on a course title by adding the following code to your theme’s functions.php file.

    function custom_course_redirect() { 
    // Get the current URL
    $current_url = home_url(add_query_arg(array(), $_SERVER['REQUEST_URI']));
    // Define the course-checkout mapping
    $redirects = array( 'https://example.com/courses/new-course-1/' => 'https://example.com/courses/new-course-1/lesson/lesson-1/' );
    // Check if the current URL matches one of the course pages
    if ( is_user_logged_in() && array_key_exists($current_url, $redirects)) { wp_redirect($redirects[$current_url]); exit(); }
    else { wp_redirect('https://example.com/dashboard/');
    exit(); }
    }
    add_action('template_redirect', 'custom_course_redirect');

    I hope this explanation is clear. If you need further assistance or a different solution, please feel free to let me know. We’re here to help!

    Best Regards,

    Srijoni

    Thread Starter Augusto Gentile

    (@agugentile)

    Hi, thanks for your help. I think it would be better to be like this the official plugin. I cannot find it useful to redirect user to the course instead the lesson.

    I tried the provided solution but I got an error in my browser “too many redirects”

    Thread Starter Augusto Gentile

    (@agugentile)

    I modified the templates/loop/course-continue.php file to bypass the user course progress check and always display a custom button. This solution is working as intended. After purchasing a course, users are directed to the dashboard. However, they would prefer to go directly to the lesson instead of the course preview. This behavior should be updated in the master Tutor LMS, as it currently causes compatibility issues with Elementor.

    https://github.com/agugentile/tutorlms/blob/main/templates/loop/course-continue.php

    Hello @agugentile,

    Thank you for sharing your feedback and for customizing the course-continue.php template. I’m glad to hear that the solution works as intended for you.

    Regarding the issue you’re facing with the redirect after course purchase, I understand that you’d prefer users to be taken directly to the first lesson instead of the course preview page. This is a great suggestion, and I can see how it would improve the user experience.

    I recommend submitting this behavior request to the Tutor LMS development team for consideration in future updates. If we get more requests to integrate this feature, we will definitely add this to our future update.

    In the meantime, if you need further clarification, then let us know. We are here for you.

    Best regards,

    Sunjida

    irisbarlev

    (@irisbarlev)

    Dear Support Team,

    I am reaching out regarding an issue I am experiencing, which has also been mentioned by other users. After purchasing a course, users are redirected to the homepage instead of directly to the first lesson of the course.

    I kindly request that users who have purchased a course be redirected directly to the first lesson of the course, rather than having to navigate through the course entry page again. This would significantly improve the user experience and streamline navigation after the purchase.

    I would appreciate your assistance in addressing this issue as soon as possible.

    Thank you in advance for your help!

    Best regards,

    Iris

    Thread Starter Augusto Gentile

    (@agugentile)

    // Add custom course continue button to replace the default logic.

    add_filter( 'tutor_course/loop/start/button', function ( $enroll_btn, $course_id ) {

    ? ? if ( ! function_exists( 'get_first_lesson_url' ) ) {

    ? ? ? ? // Function to get the first lesson or fallback to course URL.

    ? ? ? ? function get_first_lesson_url( $course_id ) {

    ? ? ? ? ? ? $lesson_url = tutor_utils()->get_course_first_lesson(); // Get the first lesson URL.

    ? ? ? ? ? ? // Fallback to course URL if no lesson is found.

    ? ? ? ? ? ? if ( ! $lesson_url ) {

    ? ? ? ? ? ? ? ? $lesson_url = get_permalink( $course_id );

    ? ? ? ? ? ? }

    ? ? ? ? ? ? return $lesson_url;

    ? ? ? ? }

    ? ? }

    ? ? // Get the first lesson URL for the button.

    ? ? $lesson_url = get_first_lesson_url( $course_id );

    ? ? // Replace the default button with your custom logic.

    ? ? $enroll_btn = '<a href="' . esc_url( $lesson_url ) . '" class="tutor-btn tutor-btn-primary">

    ?? ? ? ? ? ? ? ? ? ? ? ' . esc_html__( 'Go to the course', 'tutor' ) . '

    ?? ? ? ? ? ? ? ? ? </a>';

    ? ? return $enroll_btn;

    }, 10, 2 );

    Try adding this snippet

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.