Advertisement
jace-vrwa

vrwa-customizations.php

Dec 12th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.94 KB | None | 0 0
  1.     <?php
  2. /*
  3. Plugin Name: Add-on vtruralwater.org
  4. Description: Special code for vtruralwater.org to customize the CSV file used exporting registrations from Event Espresso.
  5.  
  6. */
  7. /* Begin Adding Functions Below This Line;  Opening PHP tag at top! */
  8. add_filter('acf/settings/enqueue_datepicker', '__return_false');
  9.  
  10. /* Add filter to pull Venue details */
  11.  
  12. add_filter(
  13.     'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
  14.     'espresso_add_venue_to_report',
  15.     10,
  16.     2
  17. );
  18. function espresso_add_venue_to_report( $reg_csv_array, $reg_row ) {
  19.     $event_id = $reg_row['Registration.EVT_ID'];
  20.     $event = EEM_Event::instance()->get_one_by_ID( $event_id );
  21.     if ( $event instanceof EE_Event ) {
  22.         $venue = $event->get_first_related( 'Venue' );
  23.         if ( $venue instanceof EE_Venue ) {
  24.             $venue_name = !empty( $venue ) ? $venue->name() : '';
  25.             $reg_csv_array['Venue'] = $venue_name;
  26.         }
  27.     }
  28.  
  29.  
  30.    
  31. $reg_csv_array['Course Proctor'] = $event->get_post_meta('Course_Proctor', true);
  32. $reg_csv_array['Course ID'] = $event->get_post_meta('Course_ID', true);
  33. $reg_csv_array['TCH'] = $event->get_post_meta('TCH', true);
  34. $reg_csv_array['Water Credit'] = $event->get_post_meta('Water_Credit', true);
  35. $reg_csv_array['Wastewater Credit'] = $event->get_post_meta('Wastewater_Credit', true);
  36.  
  37.     return $reg_csv_array;
  38.  
  39. }
  40.  
  41.  
  42.  
  43. /*
  44.  * This next big function allows us to set an array of 'allowed' fields that will be output to the registration CSV.
  45.  * 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.
  46.  */
  47.  
  48. function tw_ee_espresso_reg_report_filter_columns_ordered($csv_row, $registration_db_row)
  49.  
  50. {
  51.  
  52.     // Set the allowed fields here and also set them in the order you want them to be displayed within the CSV
  53.  
  54.     $allowed_fields_in_order = array(
  55.  
  56.         __('First Name', 'event_espresso'),
  57.  
  58.         __('Last Name', 'event_espresso'),
  59.  
  60.         __('System or Organization', 'event_espresso'),
  61.  
  62.         __('Registration\'s share of the transaction total', 'event_espresso'),
  63.  
  64.         __('Registration Status', 'event_espresso'),
  65.  
  66.         __('Payment Methods', 'event_espresso'),
  67.  
  68.         __('Gateway Transaction IDs', 'event_espresso'),
  69.  
  70.         __('Check Number', 'event_espresso'),
  71.  
  72.         __('Billing Name', 'event_espresso'),
  73.  
  74.         __('Address Part 1', 'event_espresso'),
  75.  
  76.         __('Address Part 2', 'event_espresso'),
  77.  
  78.         __('City', 'event_espresso'),
  79.  
  80.         __('State', 'event_espresso'),
  81.  
  82.         __('ZIP/Postal Code', 'event_espresso'),
  83.  
  84.         __('Billing Email', 'event_espresso'),
  85.  
  86.         __('Billing Phone', 'event_espresso'),
  87.  
  88.         __('Email Address', 'event_espresso'),
  89.  
  90.         __('Phone', 'event_espresso'),
  91.  
  92.         __('notes', 'event_espresso'),
  93.  
  94.         __('Event', 'event_espresso'),
  95.  
  96.         __('Datetimes of Ticket', 'event_espresso'),
  97.  
  98.         __('Venue', 'event_espresso'),
  99.  
  100.         __('Course Proctor', 'event_espresso'),
  101.  
  102.         __('Course ID', 'event_espresso'),
  103.  
  104.         __('TCH', 'event_espresso'),
  105.  
  106.         __('Water Credit', 'event_espresso'),
  107.  
  108.         __('Wastewater Credit', 'event_espresso'),
  109.  
  110.         __('Unique Code for this registration', 'event_espresso'),
  111.  
  112.         __('Transaction ID', 'event_espresso'),
  113.  
  114.  
  115.  
  116.     );
  117.     // Text for copy paste:    __('field', 'event_espresso'),
  118.  
  119.  
  120.     // Flip the array so the values are now the keys.
  121.  
  122.     $allowed_fields_in_order = array_flip($allowed_fields_in_order);
  123.  
  124.    
  125.  
  126.     // Set the value for each of the array elements to an empty string.
  127.  
  128.     // This is incase any of the above questions do not exist in the current registration's questions,
  129.  
  130.     // they still need to be included in the row but the value should be nothing.
  131.  
  132.     $allowed_fields_in_order = array_fill_keys(array_keys($allowed_fields_in_order), '');
  133.  
  134.    
  135.  
  136.     // Sets $filtered_csv_row to only contain the 'allowed' fields.
  137.  
  138.     $filtered_csv_row = array_intersect_key(
  139.  
  140.         $csv_row,
  141.  
  142.         $allowed_fields_in_order
  143.  
  144.     );
  145.  
  146.  
  147.  
  148.     // Now lets set $filtered_csv_row to use the same custom order we set $allowed_fields_in_order to
  149.  
  150.     $filtered_csv_row = array_merge($allowed_fields_in_order, $filtered_csv_row);
  151.  
  152.  
  153.  
  154.     return $filtered_csv_row;
  155.  
  156. }
  157.  
  158. add_filter('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'tw_ee_espresso_reg_report_filter_columns_ordered', 10, 2);
  159.  
  160.  
  161.  
  162. // This filter function replaces the text of the button for Add to Event Cart
  163. function rename_event_cart() {
  164.     return 'Cart';
  165. }
  166. add_filter('FHEE__EED_Multi_Event_Registration__set_definitions__event_cart_name','rename_event_cart');
  167.  
  168. /*
  169.  * 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.
  170.  * For example if you collect 'Parent Information' on the primary registrant only and then only child names for additional registrants,
  171.  * this snippet uses the Primary registrants parent info answers additional registration in the group  on the CSV.
  172.  */
  173. add_filter('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'tw_ee_populate_additional_registrants_questions_using_primary_reg', 20, 2);
  174. function tw_ee_populate_additional_registrants_questions_using_primary_reg($reg_csv_array, $reg_row)
  175. {
  176.     if ($reg_row['Registration.REG_group_size'] > 1 && $reg_row['Registration.REG_count'] !== 1) {
  177.         // Pull the primary registrant object.
  178.         $primary_registration = EEM_Registration::instance()->get_one(
  179.             array(
  180.                 array(
  181.                     'TXN_ID'    => $reg_row['TransactionTable.TXN_ID'],
  182.                     'REG_count' => 1,
  183.                 ),
  184.             )
  185.         );
  186.         // Pull the primary registrant asnwers.
  187.         $answers = \EEM_Answer::instance()->get_all_wpdb_results(array(
  188.             array('REG_ID' => $primary_registration->ID()),
  189.             'force_join' => array('Question'),
  190.         ));
  191.         // Now fill out the questions the primary registrant answers but the registrant has not.
  192.         foreach ($answers as $answer_row) {
  193.             if ($answer_row['Question.QST_ID']) {
  194.                 $question_label = \EEH_Export::prepare_value_from_db_for_display(
  195.                     \EEM_Question::instance(),
  196.                     'QST_admin_label',
  197.                     $answer_row['Question.QST_admin_label']
  198.                 );
  199.             } else {
  200.                 $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
  201.             }
  202.             // If a value has already been set in the CSV, leave it alone.
  203.             if (!empty($reg_csv_array[ $question_label ])) {
  204.                 continue;
  205.             }
  206.             if (isset($answer_row['Question.QST_type'])
  207.                 && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state
  208.             ) {
  209.                 $reg_csv_array[ $question_label ] = \EEM_State::instance()->get_state_name_by_ID(
  210.                     $answer_row['Answer.ANS_value']
  211.                 );
  212.             } else {
  213.                 // This isn't for html, so don't show html entities
  214.                 $reg_csv_array[ $question_label ] = html_entity_decode(
  215.                     \EEH_Export::prepare_value_from_db_for_display(
  216.                         \EEM_Answer::instance(),
  217.                         'ANS_value',
  218.                         $answer_row['Answer.ANS_value']
  219.                     )
  220.                 );
  221.             }
  222.         }
  223.         // Pull the primary attendee
  224.         $primary_attendee = $primary_registration->attendee();
  225.        
  226.         // Which primary attendee fields are including:
  227.         $att_fields_to_include = array(
  228.             'ATT_address',
  229.             'ATT_address2',
  230.             'ATT_city',
  231.             'STA_ID',
  232.             'CNT_ISO',
  233.             'ATT_zip',
  234.             'ATT_phone',
  235.         );
  236.         // add attendee columns
  237.         foreach ($att_fields_to_include as $att_field_name) {
  238.             $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
  239.             $column_name = EEH_Export::get_column_name_for_field($field_obj);
  240.             if (empty($reg_csv_array[ $column_name ])) {
  241.                 if ($att_field_name == 'STA_ID') {
  242.                     $value = $primary_attendee->state_name();
  243.                 } elseif ($att_field_name == 'CNT_ISO') {
  244.                     $value = $primary_attendee->country_name();
  245.                 } else {
  246.                     $value = EEH_Export::prepare_value_from_db_for_display(
  247.                         EEM_Attendee::instance(),
  248.                         $att_field_name,
  249.                         $primary_attendee->get($att_field_name)
  250.                     );
  251.                 }
  252.                 $reg_csv_array[ $column_name ] = $value;
  253.             }
  254.         }
  255.     }
  256.     return $reg_csv_array;
  257. }
  258.  
  259.  /* This function stops the "add new state/province" link from appearing */
  260.  
  261. add_action( 'wp_loaded', 'my_remove_new_state_form' );
  262. function my_remove_new_state_form() {
  263.     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 );
  264.     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 );
  265. }
  266.  
  267. /* This function changes the URL of the Event list for the "Back to Events List" button */
  268.  
  269. function ee_mer_change_event_list_url(){
  270.     return 'https://vtruralwater.org/training/schedule/';
  271.  
  272.  
  273.  
  274. add_filter( 'FHEE__EED_Multi_Event_Registration__set_definitions__events_list_url', 'ee_mer_change_event_list_url' );
  275.  
  276. }
  277.  /* Remove QTY from ticket selectors */
  278. function tw_ee_custom_qty_text() {
  279.     return '';
  280.  
  281. add_filter( 'FHEE__ticket_selector_chart_template__table_header_qty', 'tw_ee_custom_qty_text' );
  282. }
  283.  /* Stop Adding Functions */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement