Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Add-on vtruralwater.org
- Description: Special code for vtruralwater.org to customize the CSV file used exporting registrations from Event Espresso.
- */
- /* Begin Adding Functions Below This Line; Opening PHP tag at top! */
- add_filter('acf/settings/enqueue_datepicker', '__return_false');
- /* Add filter to pull Venue details */
- 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 ) {
- $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;
- }
- }
- $reg_csv_array['Course Proctor'] = $event->get_post_meta('Course_Proctor', true);
- $reg_csv_array['Course ID'] = $event->get_post_meta('Course_ID', true);
- $reg_csv_array['TCH'] = $event->get_post_meta('TCH', true);
- $reg_csv_array['Water Credit'] = $event->get_post_meta('Water_Credit', true);
- $reg_csv_array['Wastewater Credit'] = $event->get_post_meta('Wastewater_Credit', true);
- return $reg_csv_array;
- }
- /*
- * This next big function allows us 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(
- __('First Name', 'event_espresso'),
- __('Last Name', 'event_espresso'),
- __('System or Organization', 'event_espresso'),
- __('Registration\'s share of the transaction total', 'event_espresso'),
- __('Registration Status', 'event_espresso'),
- __('Payment Method(s)', 'event_espresso'),
- __('Gateway Transaction ID(s)', 'event_espresso'),
- __('Check Number', 'event_espresso'),
- __('Billing Name', 'event_espresso'),
- __('Address Part 1', 'event_espresso'),
- __('Address Part 2', 'event_espresso'),
- __('City', 'event_espresso'),
- __('State', 'event_espresso'),
- __('ZIP/Postal Code', 'event_espresso'),
- __('Billing Email', 'event_espresso'),
- __('Billing Phone', 'event_espresso'),
- __('Email Address', 'event_espresso'),
- __('Phone', 'event_espresso'),
- __('notes', 'event_espresso'),
- __('Event', 'event_espresso'),
- __('Datetimes of Ticket', 'event_espresso'),
- __('Venue', 'event_espresso'),
- __('Course Proctor', 'event_espresso'),
- __('Course ID', 'event_espresso'),
- __('TCH', 'event_espresso'),
- __('Water Credit', 'event_espresso'),
- __('Wastewater Credit', 'event_espresso'),
- __('Unique Code for this registration', 'event_espresso'),
- __('Transaction ID', 'event_espresso'),
- );
- // Text for copy paste: __('field', '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);
- // This filter function replaces the text of the button for Add to Event Cart
- function rename_event_cart() {
- return 'Cart';
- }
- add_filter('FHEE__EED_Multi_Event_Registration__set_definitions__event_cart_name','rename_event_cart');
- /*
- * This function can be used to populate empty additional registrant's questions using the answers proivded byt the primary registrant in the Registration CSV report.
- * For example if you collect 'Parent Information' on the primary registrant only and then only child names for additional registrants,
- * this snippet uses the Primary registrants parent info answers additional registration in the group on the CSV.
- */
- add_filter('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'tw_ee_populate_additional_registrants_questions_using_primary_reg', 20, 2);
- function tw_ee_populate_additional_registrants_questions_using_primary_reg($reg_csv_array, $reg_row)
- {
- if ($reg_row['Registration.REG_group_size'] > 1 && $reg_row['Registration.REG_count'] !== 1) {
- // Pull the primary registrant object.
- $primary_registration = EEM_Registration::instance()->get_one(
- array(
- array(
- 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
- 'REG_count' => 1,
- ),
- )
- );
- // Pull the primary registrant asnwers.
- $answers = \EEM_Answer::instance()->get_all_wpdb_results(array(
- array('REG_ID' => $primary_registration->ID()),
- 'force_join' => array('Question'),
- ));
- // Now fill out the questions the primary registrant answers but the registrant has not.
- foreach ($answers as $answer_row) {
- if ($answer_row['Question.QST_ID']) {
- $question_label = \EEH_Export::prepare_value_from_db_for_display(
- \EEM_Question::instance(),
- 'QST_admin_label',
- $answer_row['Question.QST_admin_label']
- );
- } else {
- $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
- }
- // If a value has already been set in the CSV, leave it alone.
- if (!empty($reg_csv_array[ $question_label ])) {
- continue;
- }
- if (isset($answer_row['Question.QST_type'])
- && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state
- ) {
- $reg_csv_array[ $question_label ] = \EEM_State::instance()->get_state_name_by_ID(
- $answer_row['Answer.ANS_value']
- );
- } else {
- // This isn't for html, so don't show html entities
- $reg_csv_array[ $question_label ] = html_entity_decode(
- \EEH_Export::prepare_value_from_db_for_display(
- \EEM_Answer::instance(),
- 'ANS_value',
- $answer_row['Answer.ANS_value']
- )
- );
- }
- }
- // Pull the primary attendee
- $primary_attendee = $primary_registration->attendee();
- if(! $primary_attendee instanceof EE_Attendee) {
- return $reg_csv_array;
- }
- // Which primary attendee fields are including:
- $att_fields_to_include = array(
- 'ATT_address',
- 'ATT_address2',
- 'ATT_city',
- 'STA_ID',
- 'CNT_ISO',
- 'ATT_zip',
- 'ATT_phone',
- );
- // add attendee columns
- foreach ($att_fields_to_include as $att_field_name) {
- $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
- $column_name = EEH_Export::get_column_name_for_field($field_obj);
- if (empty($reg_csv_array[ $column_name ])) {
- if ($att_field_name == 'STA_ID') {
- $value = $primary_attendee->state_name();
- } elseif ($att_field_name == 'CNT_ISO') {
- $value = $primary_attendee->country_name();
- } else {
- $value = EEH_Export::prepare_value_from_db_for_display(
- EEM_Attendee::instance(),
- $att_field_name,
- $primary_attendee->get($att_field_name)
- );
- }
- $reg_csv_array[ $column_name ] = $value;
- }
- }
- }
- return $reg_csv_array;
- }
- /* This function stops the "add new state/province" link from appearing */
- add_action( 'wp_loaded', 'my_remove_new_state_form' );
- function my_remove_new_state_form() {
- remove_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', array( 'EED_Add_New_State', 'display_add_new_state_micro_form' ), 1, 1 );
- remove_filter( 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', array( 'EED_Add_New_State', 'display_add_new_state_micro_form' ), 1, 1 );
- }
- /* This function changes the URL of the Event list for the "Back to Events List" button */
- function ee_mer_change_event_list_url(){
- return 'https://vtruralwater.org/training/schedule/';
- }
- add_filter( 'FHEE__EED_Multi_Event_Registration__set_definitions__events_list_url', 'ee_mer_change_event_list_url' );
- /* Remove QTY from ticket selectors */
- function tw_ee_custom_qty_text() {
- return '';
- }
- add_filter( 'FHEE__ticket_selector_chart_template__table_header_qty', 'tw_ee_custom_qty_text' );
- /* Stop Adding Functions */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement