Skip to content

Commit 2a2237b

Browse files
committed
Adding course title merge code for certificates.
1 parent 4186121 commit 2a2237b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php // Don't copy this line!
2+
/**
3+
* Add a {course_title} merge code to LifterLMS certificates.
4+
*
5+
* You can add this recipe to your site by creating a custom plugin
6+
* or using the Code Snippets plugin available for free in the WordPress repository.
7+
* Read this companion documentation for step-by-step directions on either method.
8+
* https://lifterlms.com/docs/adding-custom-code/
9+
*/
10+
11+
add_filter( 'llms_certificate_merge_codes', 'llms_custom_course_title_merge_code', 10, 2 );
12+
13+
function llms_custom_course_title_merge_code( $merge_codes_array, $certificate_object ){
14+
15+
// the triger post's (course's) id is in the lesson_id property of the $certificate_object
16+
$course_title = get_the_title( $certificate_object->lesson_id );
17+
18+
// add custom certificate title merge code to existing ones
19+
$merge_codes_array['{course_title}'] = $course_title;
20+
21+
// return new merge code list
22+
return $merge_codes_array;
23+
}
24+
25+
add_filter( 'llms_merge_codes_for_button', 'llms_custom_course_title_merge_code_for_button', 10, 2 );
26+
27+
function llms_custom_course_title_merge_code_for_button( $codes, $screen ){
28+
// don't run on emails
29+
if( $screen->post_type != 'llms_certificate' ){
30+
return;
31+
}
32+
33+
$codes['{course_title}'] = "Course Title";
34+
35+
return $codes;
36+
}

0 commit comments

Comments
 (0)