Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Register the field
- function wpf_add_course_count_field( $meta_fields ) {
- $meta_fields['enrolled_course_count'] = array(
- 'label' => 'Enrolled Course Count',
- 'type' => 'text',
- 'group' => 'lifterlms',
- );
- return $meta_fields;
- }
- add_filter( 'wpf_meta_fields', 'wpf_add_course_count_field' );
- // Sync course count when a user is enrolled
- function wpf_count_course_enrollments( $user_id, $course_id ) {
- $student = new LLMS_Student( $user_id );
- $courses = $student->get_courses();
- wp_fusion()->user->push_user_meta( $user_id, array( 'enrolled_course_count' => count( $courses ) ) );
- }
- add_action( 'llms_user_enrolled_in_course', 'wpf_count_course_enrollments', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement