Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save actual-saurabh/a3d35ae0938d3e8cd2c93ee1c81daf73 to your computer and use it in GitHub Desktop.
Save actual-saurabh/a3d35ae0938d3e8cd2c93ee1c81daf73 to your computer and use it in GitHub Desktop.
LifterLMS Certificate Merge Code for Grades
<?php // Do not copy this line
// Copy from under this line and paste into your child theme's functions.php
add_filter( 'llms_certificate_merge_codes', 'llms_certificate_grade_merge_code', 10, 2 );
function llms_certificate_grade_merge_code( $merge_codes_array, $certificate_object ) {
// add custom certificate title merge code to existing ones. See https://github.com/gocodebox/lifterlms/blob/a1a6833c6e6bab57bf4356739463220e51f89408/includes/certificates/class.llms.certificate.user.php#L132
$merge_codes_array['{student-grade}'] = get_user_meta( $certificate_object->user_id, 'custom_field_key_1', true );
$student = new LLMS_Student( $certificate_object->user_id );
// See https://github.com/gocodebox/lifterlms/blob/237bf80035a77bacf36ca4d8e99a8f3df92407d2/includes/models/model.llms.student.php#L715-L731
$grade = $student->get_grade( $certificate_object->lesson_id );
// return new merge code list
return $merge_codes_array;
}
add_filter( 'llms_merge_codes_for_button', 'llms_custom_certificate_prefix_suffix_merge_codes_for_button', 10, 2 );
function llms_custom_certificate_title_merge_code_for_button( $codes, $screen ) {
// don't run on emails
if( $screen->post_type != 'llms_certificate' ){
return;
}
// the merge code and the text displayed on the button.
$codes['{student-grade}'] = "Course Grade";
return $codes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment