LearnDash: Course Completion Date Shortcode
Adds a [wpide_ld_completed_on] shortcode that shows the date the student completed a course, or a "not completed yet" message.
Opens WPIDE on
Code
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
return;
}
add_shortcode( 'wpide_ld_completed_on', function ( $atts ) {
$atts = shortcode_atts( array( 'course_id' => 0, 'format' => get_option( 'date_format' ), 'pending' => 'Not completed yet' ), $atts, 'wpide_ld_completed_on' );
$user_id = get_current_user_id();
$course_id = $atts['course_id'] ? absint( $atts['course_id'] ) : (int) learndash_get_course_id( get_the_ID() );
if ( ! $user_id || ! $course_id ) {
return '';
}
$time = function_exists( 'learndash_user_get_course_completed_date' )
? (int) learndash_user_get_course_completed_date( $user_id, $course_id )
: (int) get_user_meta( $user_id, 'course_completed_' . $course_id, true );
return esc_html( $time ? wp_date( $atts['format'], $time ) : $atts['pending'] );
} );
Notes
Use course_id="123" outside a course, and format="j F Y" for a custom date format.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.