Hide Retakes if the result of the quiz is higher than a certain percentage

Home Forums Legacy Support Support queries How-to & Troubleshooting Hide Retakes if the result of the quiz is higher than a certain percentage

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #343451
    Marco
    Spectator
    Hello, I followed this tutorial https://wplms.io/support/knowledge-base/remove-retake-button-if-user-have-passed-the-quiz/ It works with version 4? I would like to hideCourse Retakes if the result of the quiz is higher than a 75 percentage of correct answer and I tried to put this code in my customizer plugin:
    
    add_filter('wplms_quiz_retake_count','remove_retake_button_if_user_passed_the_quiz',10,4);
    
    function remove_retake_button_if_user_passed_the_quiz($retakes,$quiz_id,$course,$user_id){
    
    	 $user_marks=get_post_meta($quiz_id,$user_id,true);
    	 $questions = bp_course_get_quiz_questions($quiz_id,$user_id);
    	 $total = array_reduce($questions['marks'],function($carry,$item){ $carry +=$item; return $carry;});   
    	 $total_passed= $total/100*75;
    
    	 if(empty($total))
    	 return $retakes;
    
    	 if($user_marks >= $total_passed) {
    	?>
    	<style>	.course_retake > a{
    	display:none !important;} </style>
    	<?php
    
    	 return 0; 
    	}
    	else
    	return $retakes;
    }
    
    Thank you for any suggestion, Marco
    #343467
    Marco
    Spectator
    Sorry, there was a mistake in the code, I modified with this
    
    add_filter('wplms_course_retake_count',function($count,$course_id,$user_id){
          $status = bp_course_get_user_course_status($user_id,$course_id);
          if($status == 4){
              $marks = bp_course_get_marks($user_id,$course_id);
              $passing_per = 75;
              if($marks > $passing_per){
                  return 0;
              }
          }
    
          return $count;
      },999,3);
    
    
    and now it works, please close this topic. Marco
    #343547
    Diana
    Participant
    Ohh, Okay Great Thanks for correcting and posting here for other users. This would be a great help Closing this topic
Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Hide Retakes if the result of the quiz is higher than a certain percentage’ is closed to new replies.