Advertisement
verygoodplugins

Untitled

Apr 17th, 2020
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. // Register the field
  2.  
  3. function wpf_add_course_count_field( $meta_fields ) {
  4.  
  5.     $meta_fields['enrolled_course_count'] = array(
  6.         'label' => 'Enrolled Course Count',
  7.         'type'  => 'text',
  8.         'group' => 'lifterlms',
  9.     );
  10.  
  11.     return $meta_fields;
  12.  
  13. }
  14.  
  15. add_filter( 'wpf_meta_fields', 'wpf_add_course_count_field' );
  16.  
  17. // Sync course count when a user is enrolled
  18.  
  19. function wpf_count_course_enrollments( $user_id, $course_id ) {
  20.  
  21.     $student = new LLMS_Student( $user_id );
  22.  
  23.     $courses = $student->get_courses();
  24.  
  25.     wp_fusion()->user->push_user_meta( $user_id, array( 'enrolled_course_count' => count( $courses ) ) );
  26.  
  27. }
  28.  
  29. add_action( 'llms_user_enrolled_in_course', 'wpf_count_course_enrollments', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement