Skip Navigation

[Resolved] learndash certificate

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 13 replies, has 2 voices.

Last updated by Waqar 12 months ago.

Assisted by: Waqar.

Author
Posts
#2664319

Tell us what you are trying to do? get field information from course to certificate

Is there any documentation that you are following? So I found this: https://toolset.com/forums/topic/display-custom-field-added-to-learn-dash-quiz-in-certificate/ which is great and all, but the ID part won't work. I need the certificate template to display the related course information, not just a single course ID's information

Is there a similar example that we can see? I actually opened one of these earlier this morning but it doesn't appear in my profile, no idea why

What is the link to your site? netaxschool.com

#2664441

Hi,

Thank you for contacting us and I'd be happy to assist.

That ticket that you referenced is old and it is possible that some changes have been introduced since then.

To troubleshoot this, I'll need to see exactly how and where you're trying to get the related course information. Can you please share temporary admin login details, along with the exact steps to see the missing ID?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

#2665747

Hi Janet,

Thank you for sharing these details.

I tried to login to the admin area, but keep redirecting back to the logout link.

Can you please test these credentials and see if any further action is required to be able to login as this user?

regards,
Waqar

#2666151

HI, try it again, not sure what happened. I just tested it in firefox and it worked

#2666581

I was able to access the website's admin area, thank you.

I did some research and LearnDash does seem to offer shortcodes, to display the related course's information:
hidden link

For the cases, where you need to get the raw ID of the related course, to be used in other shortcodes (for example in Toolset's Fields API's 'item' attribute - https://toolset.com/documentation/customizing-sites-using-php/functions/ ), you can register a custom shortcode, that uses the 'learndash_get_course_id' function from 'LearnDash':
hidden link

For example:


add_shortcode('custom_get_course_id', 'custom_get_course_id_func');
function custom_get_course_id_func() {
	$course_id = learndash_get_course_id();
	return $course_id;
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

Next, please add "custom_get_course_id" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

I hope this helps and please let me know if you need further assistance.

#2666671

Hi Waqar,
I need toolset specifically for doing this, so I'm learning as I go. Here's what I still do not understand:

>>I don't know how to do this:
For the cases, where you need to get the raw ID of the related course, to be used in other shortcodes (for example in Toolset's Fields API's 'item' attribute - https://toolset.com/documentation/customizing-sites-using-php/functions/ ), you can register a custom shortcode, that uses the 'learndash_get_course_id' function from 'LearnDash':
hidden link

>>what does "register" mean in this context? Where do I do this?

For example:

add_shortcode('custom_get_course_id', 'custom_get_course_id_func');
function custom_get_course_id_func() {
$course_id = learndash_get_course_id();
return $course_id;
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
>>I don't know how to include snippets in Toolset's custom code. I did try to use a snippets plugin, though (before I got toolset), and it broke my site, and I had to delete it. I try not to mess with the active theme's functions.php file for the same reasons.

Next, please add "custom_get_course_id" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
>>I have absolutely no idea how to do this, either

I hope this helps and please let me know if you need further assistance.
Thanks. I've been trying to learn Toolset, but it's all stuff like recipes and feels like I'm not any closer to being able to do what I need. If you're able to make a screencast for me, or even call & walk me through, I'd be so happy.

oh, also, I know LearnDash has shortcodes—although all of those are also gutenberg blocks, a couple of which I'm using— unfortunately none of those options listed helps me, as they won't get the custom field I'm trying to make with ToolSet.

#2667203

Thanks for writing back and I'll be happy to assist in more detail.

From register a custom shortcode I meant adding the custom code snippet for it at WP Admin -> Toolset -> Settings -> Custom Code.

I've added it to your website ( screenshot: hidden link ) and for future reference, we have a guide on the topic at:
https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

If you'll go to WP Admin -> Toolset -> Settings -> Front-end Content, you'll see that I've also added this newly registered custom shortcode's name 'custom_get_course_id', in the 'Third-party shortcode arguments' section.
( screenshot: hidden link )

Theoretically, this new shortcode [custom_get_course_id] should work in the LearnDash certificate builder, but it is not.

I don't have much experience or familiarity with the LearnDash plugin, but with your permission, I can download your website's clone and do some further testing on test server to investigate, why it is not working.

#2668525

Ok, it was a holiday week + a weekend here so it's been over 3 days but I need to work on this today and tomorrow. Go ahead and clone it, I really need this to work.

#2668663

Ok, so once the [custom_get_course_id] is in place, how do get the shortcode for field I've added? I added 2, because the wyswyg one allows for centering, but I'll take either. If you want to hop on a meeting and hash it all out with me, I'd be up for that.

If it helps, Advanced custom fields says it can do something like this (hidden link), but I couldn't tease apart the instructions around maps to make my simple text addition.

#2669327

Hi Waqar,
I'm worried about the time passing. If Toolset does not solve my problem I need to return it for a refund. This certificate is literally all I need it for. Also is it possible that Toolset and adding the Toolset Certificate template broke the certificates? Because the one I had to make since you changed it doesn't show up on student profiles, but the previous ones do.

#2669331

I can understand your concern and want to update you that I'm currently working on your website's clone.

Will be able to share the detailed findings, within the next few hours.

Thank you for your patience.

#2669345

Hi Waqar,
Oh that's lovely, thank you.

#2669485

Hi Waqar,
I have to bail. It's just taken too much time and cognition for something that's so simple and tiny. I'm going to have to do a garbage workaround like Google slides + delayed mail or something.

#2669635

Thank you for waiting, I did some testing around how LearnDash handles the connection between the certificates and the course.

On my test website, I was able to get the value of a custom field added by Toolset Types ( e.g. 'irs-certificate-info' ) from the Course, into the certificate, dynamically.

In the active theme's 'functions.php' file, I included this code:


// get ID of the course by Title
function custom_get_course_id_by_title( string $title = '' ): int {
    $posts = get_posts(
        array(
            'post_type'              => 'sfwd-courses',
            'title'                  => $title,
            'numberposts'            => 1,
            'update_post_term_cache' => false,
            'update_post_meta_cache' => false,
            'orderby'                => 'post_date ID',
            'order'                  => 'ASC',
            'fields'                 => 'ids'
        )
    );

    return empty( $posts ) ? get_the_ID() : $posts[0];
}

// Get course field value shortcode
add_shortcode('custom_get_course_field_value', 'custom_get_course_field_value_func');
function custom_get_course_field_value_func($atts) {
	$data = shortcode_atts( array(
		'field' => ''
	), $atts );

    $course_title = do_shortcode('[courseinfo show="course_title"]');
    $course_id = custom_get_course_id_by_title($course_title);
    $course_field_value = do_shortcode("[types field='".$data['field']."' suppress_filters='true' item='".$course_id."'][/types]");
    return $course_field_value;
}

This registers a custom shortcode [custom_get_course_field_value] that accepts the attribute 'field', to specify the slug of the target field.

For example, to get the value from the course field with slug 'irs-certificate-info', you can use this shortcode in your certificate builder:


[custom_get_course_field_value field='irs-certificate-info']

I've tested this to work successfully, when the certificate is downloaded from the course page and the quiz page, after successful completion of the course/quiz.

Note: Please make sure that the course, quiz, and certificates are correctly selected in each other's settings.

The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/