Coursepress Pro - Assessment Percentage in Certificate

Is it possible to display the assessment grade eg 76% within the certificate?

  • Luís

    Hi Tom ,

    Hope you're doing well today!

    CoursePress don't have any option to do display the overall grade on the certificate, if I am not missing something. I think it would be a great feature so, I've just moved this over to our Features and Feedback section, so it can be taken into consideration for the next plugin updates.

    However, I flagged the SLS team (our code experts :slight_smile: ) to investigate further and get their valuable feedback about this.

    Since this team deals with more advanced threads it may take them longer to reply.

    Cheers, Luís

  • Lindeni Mahlalela

    Hi Tom,

    I hope you are doing great today. I am very sorry for the delayed response from our side and thank you very much for you patience so far. When was was going through some old threads, I have noticed that this one is still open, so I was wondering if you still need help with this one.

    if I understood your query very well, you want to display the assessment grade on the certificate for the student. So for example, if student enrolls in course A and finishes it with a final assessment of 80%, then you want this assessment percentage/grade to appear in their certificate. If that is the case, you may try the following plugin code:

    <?php
    /**
    * Plugin Name: CoursePress Percentage on Certificate
    * Description: Add student grade on certificate_tokens
    */
    add_filter( 'coursepress_certificate_fields', 'percentage_fields_on_certificate' );
    add_filter( 'coursepress_basic_certificate_html', 'modify_basic_certificate_html', 10, 3 );
    add_filter( 'coursepress_basic_certificate_vars', 'percentage_to_certificate_vars', 10, 1 );
    
    function percentage_fields_on_certificate($fields, $student, $course){
    	$course_grade = 0;
    	if ( class_exists ( 'CoursePress_Data_Student' ) ) {
    		$course_grade = CoursePress_Data_Student::average_course_responses( $student_id, $course_id );
    	}
    	elseif ( class_exists( 'Student' ) ) {
    		$student = new Student( $student_id );
    		if ( $student->is_course_complete( $student_id, $course_id ) ) {
    			$course_grade = get_avarage_response_grade( $course_id );
    		}
    	}
    
    	return array_merge( $fields, array( 'assessment_percentage' => $course_grade ) );
    }
    
    function modify_basic_certificate_html( $html, $course_id, $student_id ) {
    	$course_grade = CoursePress_Data_Student::average_course_responses( $student_id, $course_id );
    	return '<div id="student_grade">' . $course_grade . '</div>' . $html;
    }
    
    function percentage_to_certificate_vars( $certificate_tokens ) {
    	return array_merge( $certificate_tokens, array( 'ASSESSMENT_PERCENTAGE'=>'' ) );
    }

    All you have to do is copy the above code, paste it in a new PHP file like 'assessment-grade-in-certificate.php', save an upload the code to your website in the folder '/wp-content/plugins' and activate it like you activate any other plugin, or upload it to '/wp-content/mu-plugins/' folder and it will be automatically included without the need for activation.

    Please note that the above code is just a rough overview of what you should try to achieve your goal. It may work as it is, but I haven't tested it yet. Please try it and let us know if that helps or not, let us know if you have any further questions.

    Cheers,
    Mahlamusa

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.