Add email field in course stats to download

Please add this code in your wplms-customizer.php file in wplms-customizer plugin :

add_filter('wplms_course_stats_list','add_custom_course_stat');
add_action('wplms_course_stats_process','process_custom_course_stat',10,6);

function add_custom_course_stat($list){
         $list['user_field']= 'Email';
         return $list;
        }
          
        function process_custom_course_stat(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field){
          if($field != 'user_field') // Ensures the field was checked.
             return;
          $title=__('Email','vibe');
          if(!in_array($title,$csv_title))
            $csv_title[$i]=$title;
           $field_val = get_user_by( 'id', $user_id);
            
                       
          if(isset($field_val->user_email ) && $field_val->user_email )
            $csv[$i][]= $field_val->user_email ;
          else
            $csv[$i][]= 'N.A';
          
         }

DO not forget to recalculate the stats by clicking on the calculator icon below before processing the stats .

Leave a Reply

Your email address will not be published. Required fields are marked *