auto trigger finish course when user passes quiz

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

add_action('wp_footer',function ($quiz_id,$marks,$user_id){
  
    ?>
    <script>
    function check_quiz_marks(){
      var qid = jQuery('.course_timeline ul li.active a').data('unit');
      jQuery.ajax({
          type: "POST",
          url: ajaxurl,
          dataType: 'json',
          data: { action: 'check_quiz_marks', 
                  security: $('#hash').val(),
                  quiz_id:qid,
                },
          cache: false,
          success: function (json) {
            console.log(json);
            if(json && json.status){
              var value= parseInt($('.course_progressbar').attr('data-value'));
              if(value >= 100){
                $('input[name="submit_course"]').trigger('click');
              }else{

                 $('input[name="submit_course"]').addClass('hide');
              }
            }
          }
      });
    }
    jQuery(document).ready(function($){
      $('.unit_content').on('unit_traverse',function(){
        check_quiz_marks();
        console.log('unit_content');
      });
      $('.course_progressbar').on('increment',function(){
        check_quiz_marks();
        console.log('course_progressbar');
      });
      console.log('ahava me');
        check_quiz_marks();
    });
    </script>
    <?php
      
},10);
add_action('wp_ajax_check_quiz_marks',function (){
  $quiz_id= $_POST['quiz_id'];
  if ( !isset($_POST['security']) || !wp_verify_nonce($_POST['security'],'security') || !is_numeric($quiz_id)){
     _e('Security check Failed. Contact Administrator.','vibe');
     die();
  }
  $user_id  = get_current_user_id();
  $passing_marks = get_post_meta($quiz_id,'vibe_quiz_passing_score',true);
  $marks = get_post_meta($quiz_id,$user_id,true);
  if($marks > $passing_marks){
    echo json_encode(array(
        'status' => 1,
      ));
  }else{
    echo json_encode(array(
        'status' => 0,
      ));
  }
  die();
});

 

Was this article helpful?

Related Articles

Leave A Comment?