cant continue course when auto trigger finish course and auto mark complete unit is activated

This issue appears when you have enabled “Auto trigger finish course button ” from wp-admin -> lms -> settings .
This issue appears because when user finish the quiz then system counts that quiz as finished and user progress is incremented .Hence when user reaches course page course detects that progress is 100% , lets finish this course for the user without knowing that user might retake the quiz to get better marks in it .

So to fix this please try adding this given code in your wplms-customizer.php file in wplms customizer plugin :

add_action('init','check_finish_course_auto_trigger');
function check_finish_course_auto_trigger(){
  $course_id = 0;
  if(!is_user_logged_in())
    return;
  if(isset($_POST) && isset($_POST['course_id'])){
    $course_id = $_POST['course_id'];
  }
  if(isset($_POST['no_ajax_course_id'])){
    $course_id = $_POST['no_ajax_course_id'];
  }
  if(empty($course_id ) && !empty($_COOKIE['course_id'])){
    $course_id = $_COOKIE['course_id'];
  }
  if(empty($course_id))
    return;
  global $wpdb;
  $user_id = get_current_user_id();
  $user_retakes = $wpdb->get_var($wpdb->prepare("SELECT sum(meta_value) from {$wpdb->usermeta} where user_id = %d AND meta_key in ( SELECT CONCAT('quiz_retakes_',post_id) from {$wpdb->postmeta} where meta_key=%s and meta_value=%d)",$user_id ,'vibe_quiz_course',$course_id));
  if(empty($user_retakes)){
    $user_retakes = 0;
  }
  $quiz_retakes = $wpdb->get_var($wpdb->prepare("SELECT sum(meta_value) from {$wpdb->postmeta} where meta_key=%s AND post_id IN (select post_id from {$wpdb->postmeta} WHERE meta_key=%s AND meta_value=%d)",'vibe_quiz_retakes','vibe_quiz_course',$course_id));
  if(empty( $quiz_retakes)){
     $quiz_retakes = 0;
  }
  $remaining =  $quiz_retakes - $user_retakes;
  if($remaining >= 0 ){

    $tips = Wplms_Tips::init();
    remove_action('wplms_before_start_course',array($tips,'finish_course_auto_trigger'));
  }
}

 

Was this article helpful?

Related Articles

Leave A Comment?