Shortcode to show course duration in certificate

Please add the given code in your wplms-customizer.php file in wplms customizer plugin .

add_shortcode('certificate_course_duration', 'vibe_certificate_course_duration');
  function vibe_certificate_course_duration( $atts, $content = null ) {
     global $bp,$wpdb;
     $student_id=$_GET['u'];
     $course_id=$_GET['c'];
     $start_time = $wpdb->get_var($wpdb->prepare("SELECT date_recorded FROM {$bp->activity->table_name} WHERE type ='subscribe_course' AND item_id=%d AND component='course' AND (user_id=%d OR secondary_item_id=%d) ORDER BY id DESC LIMIT 1", $course_id,$student_id,$student_id));
     $expiry=get_user_meta($student_id,$course_id,true);
    if(isset($start_time) && $start_time)
      return  human_time_diff(strtotime($start_time),strtotime($expiry));
    else
      return '[certificate_course_duration]';
  }

Then use this shortcode in certificate : [certificate_course_duration]

Was this article helpful?

Leave A Comment?