Advertisement
jace-vrwa

Untitled

Jan 27th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.06 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 Method(s)', 'event_espresso'),
  67.  
  68. __('Gateway Transaction ID(s)', '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. if(! $primary_attendee instanceof EE_Attendee) {
  227. return $reg_csv_array;
  228. }
  229.  
  230. // Which primary attendee fields are including:
  231. $att_fields_to_include = array(
  232. 'ATT_address',
  233. 'ATT_address2',
  234. 'ATT_city',
  235. 'STA_ID',
  236. 'CNT_ISO',
  237. 'ATT_zip',
  238. 'ATT_phone',
  239. );
  240. // add attendee columns
  241. foreach ($att_fields_to_include as $att_field_name) {
  242. $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
  243. $column_name = EEH_Export::get_column_name_for_field($field_obj);
  244. if (empty($reg_csv_array[ $column_name ])) {
  245. if ($att_field_name == 'STA_ID') {
  246. $value = $primary_attendee->state_name();
  247. } elseif ($att_field_name == 'CNT_ISO') {
  248. $value = $primary_attendee->country_name();
  249. } else {
  250. $value = EEH_Export::prepare_value_from_db_for_display(
  251. EEM_Attendee::instance(),
  252. $att_field_name,
  253. $primary_attendee->get($att_field_name)
  254. );
  255. }
  256. $reg_csv_array[ $column_name ] = $value;
  257. }
  258. }
  259. }
  260. return $reg_csv_array;
  261. }
  262.  
  263. /* This function stops the "add new state/province" link from appearing */
  264.  
  265. add_action( 'wp_loaded', 'my_remove_new_state_form' );
  266. function my_remove_new_state_form() {
  267. 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 );
  268. 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 );
  269. }
  270.  
  271. /* This function changes the URL of the Event list for the "Back to Events List" button */
  272.  
  273. function ee_mer_change_event_list_url(){
  274. return 'https://vtruralwater.org/training/schedule/';
  275. }
  276.  
  277.  
  278. add_filter( 'FHEE__EED_Multi_Event_Registration__set_definitions__events_list_url', 'ee_mer_change_event_list_url' );
  279.  
  280.  
  281. /* Remove QTY from ticket selectors */
  282. function tw_ee_custom_qty_text() {
  283. return '';
  284.  
  285. }
  286. add_filter( 'FHEE__ticket_selector_chart_template__table_header_qty', 'tw_ee_custom_qty_text' );
  287.  
  288. /* Stop Adding Functions */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement