• Resolved dartanidi

    (@dartanidi)


    Hi there,

    all my courses end with a quiz. Unfortunately there is no way to set something that put on screen anything like a congratulation message for having succesfully attended the course, so I tried to use the ‘lifterlms_course_completed’ hook and do a redirection, without luck.

    I tried to use wp_redirect or window.open methods, but in every case everything remains stuck at the finished quiz.

    Is there a way to do something like it?

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Nick Mariano

    (@reddotinmotion)

    Hi @dartanidi,

    In this case, the following JavaScript code snippet below will redirect the student to Google once the course is complete. So you just need to replace "https://www.google.com/" with your desired URL inside double quotes. To add the code below to your site, please follow the instructions in lifterlms.com/docs/how-do-i-add-custom-code-to-lifterlms/#code-snippets.

    add_action( "wp_footer", "custom_redirect_logic_for_lessons", PHP_INT_MAX );
    function custom_redirect_logic_for_lessons() {
    if ( is_singular( "lesson" ) ):
    ?>
    <script type="text/javascript">
    (function($){
    $(document).ready(function(){
    var notificationsDisplayed = false;
    var progress = '0%';
    var count = 0;

    /* Check that we are in the last lesson of a course. */
    if ( 0 == $(".llms-next-lesson").length ) {

    /* Create the timer only when we are on the last lesson of a course. */
    var timer = setInterval(function() {
    console.log("Timer running.");

    /* Every increment of 1 corresponds to 100 milliseconds. */
    count += 1;
    console.log('count: ', count);

    /* Always check the current value of the progress bar. */
    if ( $('.progress-bar-complete').length > 0 ) {
    progress = $('.progress-bar-complete').data('progress');
    }

    if ( '100%' != progress && count >= 10 ) {
    clearInterval(timer);
    console.log("Timer not running.");
    }

    /* Once the notifcation has been set to true, do not change it. */
    if ( $(".llms-notification.visible").length > 0 && false == notificationsDisplayed ) {
    notificationsDisplayed = true;
    }

    /* If notifications are not displayed within the first 1 second, stop the timer. */
    if ( !notificationsDisplayed && count >= 10 ) {
    clearInterval(timer);
    console.log("Timer not running.");
    }

    /* If notifications are displayed let's wait for 1 second before redirecting. */
    if ( notificationsDisplayed && count >= 10 ) {

    /* Don't redirect unless notifications have been displayed in the same viewing session. */
    if ( '100%' == progress && notificationsDisplayed ) {
    clearInterval(timer);
    console.log("Timer not running.");
    window.location.replace("https://www.google.com/");
    }
    }
    }, 100);
    }
    });
    })(jQuery);
    </script>
    <?php
    endif;
    }
    Thread Starter dartanidi

    (@dartanidi)

    Thank you!

    • This reply was modified 2 months, 1 week ago by dartanidi.
    Plugin Support Nick Mariano

    (@reddotinmotion)

    Hi @dartanidi,

    I’m glad we were able to help you! I am going to mark this thread as resolved now. Please reopen or post a new thread if you require further assistance.

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