Skip to content

Instantly share code, notes, and snippets.

@altuno
Created December 1, 2020 11:42
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 altuno/3a7714f61c2611fa42b2cff99d526ac2 to your computer and use it in GitHub Desktop.
Save altuno/3a7714f61c2611fa42b2cff99d526ac2 to your computer and use it in GitHub Desktop.
/*
* 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', 'event_espresso'),
__('Transaction ID', 'event_espresso'),
__('Attendee ID', 'event_espresso'),
__('Registration ID', 'event_espresso'),
__('Time registration occurred', 'event_espresso'),
__('Unique Code for this registration', 'event_espresso'),
__('Count of this registration in the group registration ', 'event_espresso'),
__('Registration\'s share of the transaction total', 'event_espresso'),
__('Currency', 'event_espresso'),
__('Registration Status', 'event_espresso'),
__('Transaction Status', 'event_espresso'),
__('Transaction Amount Due', 'event_espresso'),
__('Amount Paid', 'event_espresso'),
__('Payment Date(s)', 'event_espresso'),
__('Payment Method(s)', 'event_espresso'),
__('Gateway Transaction ID(s)', 'event_espresso'),
__('Check-Ins', 'event_espresso'),
__('Ticket Name', 'event_espresso'),
__('Datetimes of Ticket', 'event_espresso'),
__('First Name', 'event_espresso'),
__('Last Name', 'event_espresso'),
__('Email Address', 'event_espresso'),
__('Address Part 1', 'event_espresso'),
__('Address Part 2', 'event_espresso'),
__('City', 'event_espresso'),
__('State', 'event_espresso'),
__('Country', 'event_espresso'),
__('ZIP/Postal Code', 'event_espresso'),
__('Phone', 'event_espresso'),
__('Total Taxes', 'event_espresso'),
__('Event Categories', 'event_espresso'),
__('Author', 'event_espresso'),
__('Tag', 'event_espresso'),
__('Venue', 'event_espresso'),
__('Transaction Promotions', 'event_espresso'),
);
// 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);
return $filtered_csv_row;
}
add_filter('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'tw_ee_espresso_reg_report_filter_columns_ordered', 10, 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 ) {
$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
)
)
);
$sub_line_item_details = array();
foreach( $sub_line_items as $sub_line_item ) {
$sub_line_item_details[] = $sub_line_item->get_pretty( 'LIN_total', 'localized_float' );
}
$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[ 'Event_CPT.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);
}
$reg_csv_array['Event Categories'] = !empty($terms) ? $terms : null;
return $reg_csv_array;
}
add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'ee_tw_event_categories_to_csv', 10, 2 );
//* Add instructor name to EE4 CSV Download
add_filter( 'FHEE__EE_Export__report_registrations__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'];
$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__EE_Export__report_registrations__reg_csv_array', 'espresso_add_tag_to_report', 10, 2);
function espresso_add_tag_to_report( $reg_csv_array, $reg_row ) {
$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__EE_Export__report_registrations__reg_csv_array', 'espresso_add_venue_to_report', 10, 2);
function espresso_add_venue_to_report( $reg_csv_array, $reg_row ) {
$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