Disable Quiz retakes when user gets marks more than passing score

Requires WPLMS version 1.9.4+

a. Enable Quiz passing score in WP Admin – LMS – Settings

b. Set a passing score in Quiz settings.

c. Add this code in child theme functions.php or WPLMS customiser :

add_filter('wplms_quiz_retakes_left','wplms_passed_quiz_retakes',10,2);
function wplms_passed_quiz_retakes($remaining_retakes,$quiz_id){
 
$passing_score = get_post_meta($quiz_id,'vibe_quiz_passing_score',true);
if(isset($passing_score) && is_numeric($passing_score)){
    $user_id = get_current_user_id();
    $score = get_post_meta($quiz_id,$user_id,true);
    if($score > $passing_score){
        return 0;
    }
}
return $remaining_retakes;
}

 

for wplms version 3.2 or above :

 

add_filter('bp_course_fetch_user_quiz_retake_count',function ($retake_count,$quiz_id,$user_id){

$passing_score = get_post_meta($quiz_id,'vibe_quiz_passing_score',true);

if(isset($passing_score) && is_numeric($passing_score)){

$user_id = get_current_user_id();

$score = get_post_meta($quiz_id,$user_id,true);

if($score > $passing_score){

return get_post_meta($quiz_id,'vibe_quiz_retakes',true);

}

}

return $retake_count;

},10,3);