Okay
  Public Ticket #2825989
Export CSV attendees with custom fields
Closed

Comments

  •  5
    gfc-de started the conversation

    Hello,

    when exporting the attendees of an event to a CSV file, unfortunately the custom fields we added to the RSVP form in functions.php are not taken over. Is there any way to modify the code so that when exporting the attendees to a CSV file, the custom fields are also exported?

  •  5
    gfc-de replied

    Hi,


    still got this problem. Looking forward to an answer. Thank you!

  •  793
    Zhivko replied

    Is it possible to send me your custom code to check the fields?


    Stachethemes Developer

  •  5
    gfc-de replied

    See my function.php in the attached file.

  •  793
    Zhivko replied

    Add these two filters to your code:

    add_filter('stec_csv_export_attendance_fields', function($fields) {
        /**
          These seem to be the custom meta keys stored in the attendee object
          So I'm adding the keys in the attendance fields       $attendee->set_custom_data('Erziehungsberechtigte', ...
          $attendee->set_custom_data('Gebutsdatum', ...
          $attendee->set_custom_data('Straße, Hausnummer', ...
          $attendee->set_custom_data('PLZ, Stadt', ...
          $attendee->set_custom_data('Telefon', ...
          $attendee->set_custom_data('Anmerkungen', ...
          $attendee->set_custom_data('attendee_speichern', ...      */
        $merged_fields = array_merge($fields, array(
            'Erziehungsberechtigte' => esc_html__('Erziehungsberechtigte', 'stec'),
            'Gebutsdatum'           => esc_html__('Gebutsdatum', 'stec'),
            'Straße, Hausnummer'    => '"' . esc_html__('Straße, Hausnummer', 'stec') . '"', // NOTE: fields containing commas must be wrapped in double quotes
            'PLZ, Stadt'            => '"' . esc_html__('PLZ, Stadt', 'stec') . '"',
            'Telefon'               => esc_html__('Telefon', 'stec'),
            'Anmerkungen'           => esc_html__('Anmerkungen', 'stec'),
            'attendee_speichern'    => esc_html__('Erweiterter Datenschutz', 'stec'),
        ));     return $merged_fields;
    }); /**
     * Tell the calendar how to process the new attendee fields when exporting to csv
     * @params array
     * 
     *  $params = array(
     *       'case'       => $k,
     *       'event_post' => $event,
     *       'content'    => '',
     *       'attendee'   => $attendee
     *   )
     */
    add_filter('stec_csv_export_proccess_attendance_custom_fields', function($params) {     $attendee_custom_data = $params['attendee']->custom;     if ( isset($attendee_custom_data[$params['case']]) ) {
            $params['content'] = $attendee_custom_data[$params['case']];
        }     return $params;
    });

    Stachethemes Developer

  •  5
    gfc-de replied

    Wow, thank you for this code! It works great! The custom fields are in the CSV file.

    But unfortunately the name of the attendees (default field "name") are not in the list. How can I add this? 

    In addition, as written here, it would be nice if the name of the Event and not just the Event-IDs were displayed in the csv file.


  •  5
    gfc-de replied

    Hi,

    still got these two problems. Would be great to get an answer on this :)

    1. Unfortunately the name of the attendees (default field "name") are not in the list. How can I add this?

    2. In addition, as written here, it would be nice if the name of the Event and not just the Event-IDs were displayed in the csv file.



  •  793
    Zhivko replied

    Resolved in ticket #2842496


    Stachethemes Developer

  •  5
    gfc-de replied

    I'm sorry that I have to open this ticket again. This code has the problem, that after exporting as csv the name ("Vor -und Nachname") is overwritten with the beginning of the mail-address. Which part of code is wrong? Thanks for your help!

    7753726045.png

    7089475369.png


  •  793
    Zhivko replied

    What version is your calendar?


    Stachethemes Developer

  •  793
    Zhivko replied

    I believe this was a bug in version 3.2.4.

    I'll fix this problem but I'll need to know your current version.


    Stachethemes Developer

  •  5
    gfc-de replied

    3.2.4

  •  793
    Zhivko replied

    I'm attaching updated functions file.

    Could you let me know if the problem is resolved when you submit new rsvp form?


    Stachethemes Developer

  •  5
    gfc-de replied

    That works! Best thanks for your quick and good help!