Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active December 3, 2020 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pebblo/d1ab608fac2c68450dab0f458b6baa45 to your computer and use it in GitHub Desktop.
Save Pebblo/d1ab608fac2c68450dab0f458b6baa45 to your computer and use it in GitHub Desktop.
<?php
/*
* This function allows you to set an array of 'allowed' fields that will be output to the registration CSV.
* The order in which they are set in the 'allowed_fields_in_order' array is the order that will be used by the CSV itself.
*/
function tw_ee_espresso_reg_report_filter_columns_ordered($csv_row, $registration_db_row)
{
// Set the allowed fields here and also set them in the order you want them to be displayed within the CSV
$allowed_fields_in_order = array(
'Event',
'Transaction ID',
'Attendee ID',
'Registration ID',
'Time registration occurred',
'Unique Code for this registration',
'Count of this registration in the group registration ',
'Registration\'s share of the transaction total',
'Currency',
'Registration Status',
'Transaction Status',
'Transaction Amount Due',
'Amount Paid',
'Payment Date(s)',
'Payment Method(s)',
'Gateway Transaction ID(s)',
'Check-Ins',
'Ticket Name',
'Datetimes of Ticket',
'First Name',
'Last Name',
'Email Address',
'Address Part 1',
'Address Part 2',
'City',
'State',
'Country',
'ZIP/Postal Code',
'Phone',
'Total Taxes',
'Event Categories',
'Author',
'Tag',
'Venue',
'Transaction Promotions',
'ig-name-de',
'ig-text-de'
);
// Flip the array so the values are now the keys.
$allowed_fields_in_order = array_flip($allowed_fields_in_order);
// Set the value for each of the array elements to an empty string.
// This is incase any of the above questions do not exist in the current registration's questions,
// they still need to be included in the row but the value should be nothing.
$allowed_fields_in_order = array_fill_keys(array_keys($allowed_fields_in_order), '');
// Sets $filtered_csv_row to only contain the 'allowed' fields.
$filtered_csv_row = array_intersect_key(
$csv_row,
$allowed_fields_in_order
);
// Now lets set $filtered_csv_row to use the same custom order we set $allowed_fields_in_order to
$filtered_csv_row = array_merge($allowed_fields_in_order, $filtered_csv_row);
// write_log(
// array(
// 'filtered_csv_row' => $filtered_csv_row,
// 'registration_db_row' => $registration_db_row
// )
// );
return $filtered_csv_row;
}
add_filter('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'tw_ee_espresso_reg_report_filter_columns_ordered', 999, 2);
// Select Switzerland by default in the address field
add_action(
'wp_enqueue_scripts',
'my_change_default_ee_country_option',
20
);
function my_change_default_ee_country_option(){
$custom_js = 'jQuery(document).ready(function($){';
$custom_js .= '$(".ee-reg-qstn-country").val("CH");';
$custom_js .= '});';
wp_add_inline_script('ee_form_section_validation', $custom_js);
}
// Add total tax amount column to the EE4 Registrations csv download
add_filter(
'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
'espresso_add_total_taxes_column',
10,
2
);
function espresso_add_total_taxes_column( $reg_csv_array, $reg_row ) {
$sub_line_item_details = array();
$registration = EEM_Registration::instance()->get_one_by_ID( $reg_row['Registration.REG_ID'] );
if( $registration instanceof EE_Registration && $registration->is_primary_registrant() ) {
$sub_line_items = EEM_Line_Item::instance()->get_all(
array(
array(
'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
'LIN_type' => EEM_Line_Item::type_tax_sub_total
)
)
);
foreach( $sub_line_items as $sub_line_item ) {
$sub_line_item_details[] = $sub_line_item->get_pretty( 'LIN_total', 'localized_float' );
}
}
// All rows on the CSV must have the same values so add column to reg_csv_array even if it has no value.
$reg_csv_array[ __( 'Total Taxes', 'event_espresso' ) ] = implode('+', $sub_line_item_details );
return $reg_csv_array;
}
// Add event categories to EE4 csv download
function ee_tw_event_categories_to_csv( $reg_csv_array, $reg_row ) {
$EVT_ID = $reg_row['Registration.EVT_ID'];
$terms = array();
$event_categories = get_the_terms( $EVT_ID, 'espresso_event_categories' );
if ( $event_categories ) {
foreach( $event_categories as $term ) {
$terms[] = $term->name;
}
$terms = implode( ', ', $terms);
}
// All rows on the CSV must have the same values so add column to reg_csv_array even if it has no value.
$reg_csv_array['Event Categories'] = !empty($terms) ? $terms : null;
return $reg_csv_array;
}
add_filter( 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'ee_tw_event_categories_to_csv', 10, 2 );
//* Add instructor name to EE4 CSV Download
add_filter( 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'espresso_add_author_to_report', 10, 2);
function espresso_add_author_to_report( $reg_csv_array, $reg_row ) {
$event_id = $reg_row['Registration.EVT_ID'];
$reg_csv_array['Author'] = null;
$event = EEM_Event::instance()->get_one_by_ID( $event_id );
if ( $event instanceof EE_Event ) {
$post_author = get_post_field( 'post_author', $event_id );
$author_info = get_userdata( $post_author );
$reg_csv_array['Author'] = $author_info->last_name . ", " . $author_info->first_name;
}
return $reg_csv_array;
}
//* Add language tags to the CSV Download
add_filter( 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'espresso_add_tag_to_report', 10, 2);
function espresso_add_tag_to_report( $reg_csv_array, $reg_row ) {
// All rows on the CSV must have the same values so add column to reg_csv_array even if it has no value.
$reg_csv_array['Tag'] = null;
$event_id = $reg_row['Registration.EVT_ID'];
$event = EEM_Event::instance()->get_one_by_ID( $event_id );
if ( $event instanceof EE_Event ) {
$posttags = get_the_tags( $event_id );
if ($posttags) {
foreach($posttags as $tag) {
$reg_csv_array['Tag'] = $tag->name;
}
}
}
return $reg_csv_array;
}
//* Add Venue to CSV Download
add_filter( 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'espresso_add_venue_to_report', 10, 2);
function espresso_add_venue_to_report( $reg_csv_array, $reg_row ) {
// All rows on the CSV must have the same values so add column to reg_csv_array even if it has no value.
$reg_csv_array['Venue'] = null;
$event_id = $reg_row['Registration.EVT_ID'];
$event = EEM_Event::instance()->get_one_by_ID( $event_id );
if ( $event instanceof EE_Event ) {
$venue = $event->get_first_related( 'Venue' );
if ( $venue instanceof EE_Venue ) {
$venue_name = !empty( $venue ) ? $venue->name() : '';
$reg_csv_array['Venue'] = $venue_name;
}
}
return $reg_csv_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment