Add Unique ID or Order ID to LearnPress Certificate

[ad_1]

This is the code 🙂

/* EWS Change - Custom Shortcode */
function lporderid_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 = "ID Sertifikat: " . str_pad($refid, 10, '0', STR_PAD_LEFT);

    return $ordernumber;
}
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'] . ']');
        }
}
}

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer