Add custom user field in Download course stats

0. Install WPLMS customiser plugin.

1. Go to WP Admin -> Plugins ->Editor -> Wplms customizer -> customizer_class.php

2. Add this code in __construct function :

Assuming the custom user field is Location :

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

3. Add this code in the class :

 

function add_custom_course_stat($list){
         $list['user_field']= 'Location';
         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=__('Location','vibe');
          if(!in_array($title,$csv_title))
            $csv_title[$i]=$title;
          $ifield = 'Location'; 
          if(bp_is_active('xprofile'))
           $field_val= bp_get_profile_field_data( 'field='.$ifield.'&user_id=' .$user_id );
                       
          if(isset($field_val) && $field_val)
            $csv[$i][]= $field_val;
          else
            $csv[$i][]= 'N.A';
          
         }

For adding multiple fields: 

function add_custom_course_stat($list){
   $new_list = array(
                    'user_field1'=>'Location',
                    'user_field2'=>'Bio'
                    //add another element like same above 'user_field3'=>'Gender'
                     );
   
   $list=array_merge($list,$new_list);
    return $list;
}
         
 function process_custom_course_stat(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field){

    if( strpos($field, 'user_field1') === false &&  strpos($field, 'user_field2') === false)//if another field please include it here like this     if( strpos($field, 'user_field1') === false &&  strpos($field, 'user_field2') === false   &&  strpos($field, 'user_field3') === false)
        return;
    
    if($field == 'user_field1'){
 
     $title=__('Location','vibe');

      if(!in_array($title,$csv_title))
        $csv_title[$i]=$title;

      $ifield = 'Location';

      if(bp_is_active('xprofile'))
       $field_val= bp_get_profile_field_data( 'field='.$ifield.'&user_id=' .$user_id );
                  
      if(isset($field_val) && $field_val)
        $csv[$i][]= $field_val;
      else
        $csv[$i][]= 'N.A';
        return;
     }

     if($field == 'user_field2'){
   
         $title=__('Bio','vibe');

      if(!in_array($title,$csv_title))
        $csv_title[$i]=$title;
      $ifield = 'Bio';  
      if(bp_is_active('xprofile'))
       $field_val= bp_get_profile_field_data( 'field='.$ifield.'&user_id=' .$user_id );
                  
      if(isset($field_val) && $field_val)
        $csv[$i][]= $field_val;
      else
        $csv[$i][]= 'N.A';
        return;
     }

//add process doe another field like :
/*
if($field == 'user_field3'){
   
         $title=__('Gender','vibe');

      if(!in_array($title,$csv_title))
        $csv_title[$i]=$title;
      $ifield = 'Gender';  
      if(bp_is_active('xprofile'))
       $field_val= bp_get_profile_field_data( 'field='.$ifield.'&user_id=' .$user_id );
                  
      if(isset($field_val) && $field_val)
        $csv[$i][]= $field_val;
      else
        $csv[$i][]= 'N.A';
        return;
     }

*/
 }

Github gist : https://gist.github.com/MrVibe/c0ea6131147072b61dfa