Browse: Home / Snippets /

Add certificate expire date based upon course completion date

Contents


Snippet #

Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.

// expires on: [cert_expire offset="+5 years" format="M j, Y"][courseinfo show="completed_on" format="Y-m-d"][/cert_expire]
add_shortcode('cert_expire', function($atts = array(), $content = '') {
	
	if ( !empty( $content ) ) {
		// We call do_shortcode to have LD process the inner shortcode [courseinfo] section. 
		$content = do_shortcode( $content );
		if ( !empty( $content ) ) {

			// the returned value should be YYYY-MM-DD as per the inner shortcode courseinfo format 
			// so now we convert it to a timestamp and adjust per the offset. 
			$course_completed_on_timestamp = strtotime( $atts['offset'], strtotime( $content ) );
			
			// The taking that adjusted timestamp we now reformat per the cert_expire format 
			$content = date( $atts['format'], $course_completed_on_timestamp );
		} else {
			// If content is empty we set our return value to an empty string
			$content = '';
		}
	} else {
		// If content is empty we set our return value to an empty string
		$content = '';
	}

	return $content;	
});