Add custom fields to certificate
-
Hi, I use LearnPress with Certificates Addon, and now, by regulation I need to add custom fields to my certificate, like student address, a government registration number. All of those will come from checkout custom fields. How can I add them to certificate?
Thx, for help.
-
Hi @kitkaanka77
I am sorry about this. The function is not available now.
Hi @kitkaanka77
i tried:
add_filter( 'certificates/fields', function($fields) { $fields[] = array( 'name' => 'shortcode', 'icon' => 'dashicons-smiley', 'title' => __( 'Shortcode', 'learnpress-certificates' ) ); return $fields; }); if (class_exists('LP_Certificate_Layer')) { class LP_Certificate_Shortcode_Layer extends LP_Certificate_Layer { public function apply( $data ) { if (function_exists('get_field') && !empty( $data['course_id'] ) ) { $this->options['text'] = get_field('stundenanzahl', $data['course_id'] ); } else { $this->options['text'] = $this->options['text']; } } } }
in functions.php of my child theme… i have not tested it enough, but seems to work for me
Thx ?? I’ll check it ??
@kitkaanka77 Did you ever figure this out? I’m in the same boat, trying to get a shortcode to display on the certificate.
I tried @ran_alexander ‘s code above as well. It adds a custom field called “Shortcode” to the certificate editor, but as someone with little PHP experience, I’m not sure how to link it to my actual shortcode..
the option[‘text’] holds the content of the Layer.
so, do_shortcode should do the trick.be aware, that learnpress 4.0 is here and that the LP_Certificate_Layer may not be available any longer….
class LP_Certificate_Shortcode_Layer extends LP_Certificate_Layer { public function apply( $data ) { $this->options['text'] = do_shortcode('[your-code course_id="' . $data['course_id'] . ']'); } }
@ran_alexander You’re awesome! All working now. LP_Certificate_Layer is still valid, I double checked.
For those that are curious, here is the full working code in my functions.php (Including shortcode):
/* EWS Change - Custom Shortcode */ function lporderid_function() { return 'test'; } add_shortcode('lporderid', 'lporderid_function'); /* Adds new shortcode option to cert editor */ add_filter( 'certificates/fields', function($fields) { $fields[] = array( 'name' => 'shortcode', 'icon' => 'dashicons-smiley', 'title' => __( 'Shortcode', 'learnpress-certificates' ) ); return $fields; }); if (class_exists('LP_Certificate_Layer')) { class LP_Certificate_Shortcode_Layer extends LP_Certificate_Layer { public function apply( $data ) { $this->options['text'] = do_shortcode('[lporderid course_id="' . $data['course_id'] . ']'); } } }
Hi All,
@rotornut44 thanks for sharing the code.
I am a WordPress and Learnpress novice. Do you know how I can read the order number and the grade for the person’s course? I would like to use your code as a basis for doing this but I do not know how to find the order number and grade.
The idea is that the order number will be used as the unique certificate number and showing the person’s final grade on a certificate is always useful.
I will share my result when it is working.
Thanks,
Jim
I managed to get a unique ID displayed on the certificate. It uses the order number.
I am still trying to find the grade. Any suggestions appreciated.
/* * Certificate fields */ /* EWS Change - Custom Shortcode */ function lpuniqueid_function() { global $wpdb; $userid = get_current_user_id(); $courseid = get_the_ID(); $sql = "SELECT ref_id FROM wp_learnpress_user_items WHERE user_id = $userid AND item_id = $courseid;"; $refid = $wpdb->get_var($sql); $ordernumber = "#" . str_pad($refid, 10, '0', STR_PAD_LEFT); return $ordernumber; } add_shortcode('lpuniqueid', 'lpuniqueid_function'); /* Adds new shortcode option to cert editor */ add_filter( 'certificates/fields', function($fields) { $fields[] = array( 'name' => 'uniqueid', 'icon' => 'dashicons-clipboard', 'title' => __( 'Unique ID', 'learnpress-certificates' ) ); return $fields; }); if (class_exists('LP_Certificate_Layer')) { class LP_Certificate_Shortcode_Layer extends LP_Certificate_Layer { public function apply( $data ) { $this->options['text'] = do_shortcode('[lpuniqueid course_id="' . $data['course_id'] . ']'); } } }
Hi! Thanks for share!
Can you tell me how i insert my custom field in your code?
Thank you!
Hello. I am interested in adding the data from the “Custom register fields” found in LearnPress -> Settings -> ‘Profile’ tab -> ‘Custom Register Fields’ section, to my certificates. Can someone assist with this?
Please also Im….. I am interested in adding the data from the “Custom register fields” found in LearnPress -> Settings -> ‘Profile’ tab -> ‘Custom Register Fields’ section, to my certificates. Can someone assist with this?… help us please…
i want create 2 or 3 field from user in sql database to certification learnpress
i use this under code but this code are fault
please help me for add 3 field from user such as postalcode and address and fathername
in certification for one curess/* EWS Change - Custom Shortcode */ function shorman_function() { return 'test test'; } add_shortcode('shorman', 'shorman_function'); /* Adds new shortcode option to cert editor */ add_filter( 'certificates/fields', function($fields) { $fields[] = array( 'name' => 'pedar', 'icon' => 'dashicons-smiley', 'title' => __( '??? ???', 'learnpress-certificates' ) ); return $fields; }); /* EWS Change - Custom Shortcode */ function lporderid_function() { return 'test'; } add_shortcode('lporderid', 'lporderid_function'); /* Adds new shortcode option to cert editor */ add_filter( 'certificates/fields', function($fields) { $fields[] = array( 'name' => 'shortcode', 'icon' => 'dashicons-smiley', 'title' => __( '?????', 'learnpress-certificates' ) ); if (class_exists('LP_Certificate_Layer')) { class LP_Certificate_Shortcode_Layer extends LP_Certificate_Layer { public function apply( $data ) { $this->options['text'] = do_shortcode('[lporderid course_id="' . $data['course_id'] . ']'); //$this->options['text'] = do_shortcode('[shorman course_id="' . $data['course_id'] . ']'); } } } return $fields; });
i want create 2 or 3 field from user in sql database to certification learnpress i use this under code but this code are fault
please help me for add 3 field from user such as postalcode and address and fathername
in certification for one curessfunction shorman_function() {
return ‘test test’;
}
add_shortcode(‘shorman’, ‘shorman_function’);add_filter( ‘certificates/fields’, function($fields) {
$fields[] = array(
‘name’ => ‘pedar’,
‘icon’ => ‘dashicons-smiley’,
‘title’ => __( ‘??? ???’, ‘learnpress-certificates’ )
);
return $fields;
});function lporderid_function() {
return ‘test’;
}
add_shortcode(‘lporderid’, ‘lporderid_function’);/* Adds new shortcode option to cert editor */
add_filter( ‘certificates/fields’, function($fields) {
$fields[] = array(
‘name’ => ‘shortcode’,
‘icon’ => ‘dashicons-smiley’,
‘title’ => __( ‘?????’, ‘learnpress-certificates’ )
);
if (class_exists(‘LP_Certificate_Layer’)) {class LP_Certificate_Shortcode_Layer extends LP_Certificate_Layer {
public function apply( $data ) {
$this->options[‘text’] = do_shortcode(‘[lporderid course_id=”‘ . $data[‘course_id’] . ‘]’);
//$this->options[‘text’] = do_shortcode(‘[shorman course_id=”‘ . $data[‘course_id’] . ‘]’);
}}
}
return $fields;
});`HI,
I need to includ in the certificate, some custom fiels, like IDIt′s possible??
Please, let me know…
Thanks in advance!-
This reply was modified 3 years, 1 month ago by
chamorro.
Hi everyone,
Anyone else having trouble with the shortcode part of this?
Everything is working and I can set $this->options[‘text’] in the related class extension to anything straight text and it works great.
My shortcode works great on it’s own.
Combined it will not render the shortcode of even a variable.$this->options[‘text’] = do_shortcode(‘test: [myshortcode course_id=”’ . $data[‘course_id’] . ‘]’);
displays as ‘test:’ on the certification but [myshortcode] anywhere else on the site works.
-
This reply was modified 3 years, 1 month ago by
- The topic ‘Add custom fields to certificate’ is closed to new replies.