Use Grading or Pass Fail labels instead of Marks percentages

In this tip, we’ll change the reference to Course marks to Grades or Pass Fail status only. We’ve added filters in the theme which allow us to set custom grading system for specific courses or all courses. Here’s how we can do it :

1. Go to WP Admin -> Plugins -> Editor -> WPLMS Customizer -> customizer_class.php

2. Add the following line of code in the function _construct function :

PHP Code:

add_filter('wplms_course_marks',array($this,'wplms_course_passfail'),10,2);

3 a. for PASS/FAIL STATUS : Add the following code in the class :

PHP Code:
function wplms_course_passfail($marks_html,$course_id){
$extract = explode('/',$marks_html);
$course_marks = intval($extract[0]);
$certificate_val = get_post_meta($course_id,'vibe_course_passing_percentage',true);
if(isset($certificate_val) && is_numeric($certificate_val)){
  if($course_marks >= $certificate_val){
   $marks_html = 'PASS';
}elseif($course_marks==0){
  $marks_html = 'N.A';
}else{
  $marks_html = 'FAIL';
}
}
return $marks_html;
}

OR

3 b. for GRADING : Add the following code in the class :

PHP Code:

function wplms_course_passfail($marks_html,$course_id){
            $extract = explode('/',$marks_html);
            $course_marks = intval($extract[0]);
 
            $grades = array(
                100 => 'A',
                80 => 'B',
                60 => 'C',
                40 => 'D'
            );
 
            foreach($grades as $marks => $grade){
               if($course_marks <= $marks)
                  $marks_html = 'GRADE '.$grade;
            }
 
            return $marks_html;
        }

$marks_html is of the format 30/100 where 30 is the marks in the course

The grade array signifies grades as follow: 100-80 : Grade A, 80-60 : Grade B, 60-40 : Grade C, 40-0 : Grade D

Note: It requires WPLMS version 1.7.2 and above.