Advertisement
verygoodplugins

Untitled

Jun 25th, 2021
1,153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.58 KB | None | 0 0
  1.     /**
  2.      * Gets all the attendee and event meta from an attendee ID.
  3.      *
  4.      * @param  Int   $attendee_id The attendee ID.
  5.      * @return array The data to sync to the CRM.
  6.      */
  7.  
  8.     public function get_attendee_meta( $attendee_id ) {
  9.  
  10.         // Get the event ID (Tribe annoyingly stores these all in different keys)
  11.  
  12.         $event_id  = get_post_meta( $attendee_id, '_tribe_wooticket_event', true );
  13.         $ticket_id = get_post_meta( $attendee_id, '_tribe_wooticket_product', true );
  14.  
  15.         if ( empty( $event_id ) ) {
  16.             $event_id  = get_post_meta( $attendee_id, '_tribe_eddticket_event', true );
  17.             $ticket_id = get_post_meta( $attendee_id, '_tribe_eddticket_product', true );
  18.         }
  19.  
  20.         if ( empty( $event_id ) ) {
  21.             $event_id  = get_post_meta( $attendee_id, '_tribe_rsvp_event', true );
  22.             $ticket_id = get_post_meta( $attendee_id, '_tribe_rsvp_product', true );
  23.         }
  24.  
  25.         // This is a bit tricky. When Allow Individual Attendee Collection is off, this will be the purchaser's
  26.         // email. Also if it's on, but left blank.
  27.  
  28.         $attendee_email = get_post_meta( $attendee_id, '_tribe_tickets_email', true );
  29.  
  30.         if ( empty( $attendee_email ) ) {
  31.             $attendee_email = get_post_meta( $attendee_id, '_tribe_rsvp_email', true );
  32.         }
  33.  
  34.         $venue_id       = get_post_meta( $event_id, '_EventVenueID', true );
  35.         $event_date     = get_post_meta( $event_id, '_EventStartDate', true );
  36.         $event_address  = get_post_meta( $venue_id, '_VenueAddress', true );
  37.         $event_city     = get_post_meta( $venue_id, '_VenueCity', true );
  38.         $event_country  = get_post_meta( $venue_id, '_VenueCountry', true );
  39.         $event_state    = get_post_meta( $venue_id, '_VenueState', true );
  40.         $event_province = get_post_meta( $venue_id, '_VenueProvince', true );
  41.         $event_zip      = get_post_meta( $venue_id, '_VenueZip', true );
  42.  
  43.         $event_time = date( 'g:ia', strtotime( $event_date ) );
  44.  
  45.         $update_data = array(
  46.             'user_email'     => $attendee_email,
  47.             'ticket_name'    => get_the_title( $ticket_id ),
  48.             'event_name'     => get_the_title( $event_id ),
  49.             'event_date'     => $event_date,
  50.             'event_time'     => $event_time,
  51.             'venue_name'     => get_the_title( $venue_id ),
  52.             'event_address'  => $event_address,
  53.             'event_city'     => $event_city,
  54.             'event_state'    => $event_state,
  55.             'event_province' => $event_province,
  56.             'event_country'  => $event_country,
  57.             'event_zip'      => $event_zip,
  58.         );
  59.  
  60.         // Name
  61.  
  62.         $full_name = get_post_meta( $attendee_id, '_tribe_tickets_full_name', true );
  63.  
  64.         if ( empty( $full_name ) ) {
  65.             $full_name = get_post_meta( $attendee_id, '_tribe_rsvp_full_name', true );
  66.         }
  67.  
  68.         if ( ! empty( $full_name ) ) {
  69.  
  70.             $parts                     = explode( ' ', $full_name, 2 );
  71.             $update_data['first_name'] = $parts[0];
  72.  
  73.             if ( isset( $parts[1] ) ) {
  74.                 $update_data['last_name'] = $parts[1];
  75.             }
  76.         }
  77.  
  78.         // Organizer
  79.  
  80.         $organizer_id = get_post_meta( $event_id, '_EventOrganizerID', true );
  81.  
  82.         if ( ! empty( $organizer_id ) ) {
  83.  
  84.             $organizer_data = array(
  85.                 'organizer_name'    => get_the_title( $organizer_id ),
  86.                 'organizer_phone'   => get_post_meta( $organizer_id, '_OrganizerPhone', true ),
  87.                 'organizer_website' => get_post_meta( $organizer_id, '_OrganizerWebsite', true ),
  88.                 'organizer_email'   => get_post_meta( $organizer_id, '_OrganizerEmail', true ),
  89.             );
  90.  
  91.             $update_data = array_merge( $update_data, $organizer_data );
  92.  
  93.         }
  94.  
  95.         $ticket_meta = get_post_meta( $attendee_id, '_tribe_tickets_meta', true );
  96.  
  97.         if ( ! empty( $ticket_meta ) ) {
  98.  
  99.             $update_data = array_merge( $update_data, $ticket_meta );
  100.  
  101.             // Cases where a custom email field needs to take priority over the standard email field
  102.  
  103.             foreach ( $ticket_meta as $key => $value ) {
  104.  
  105.                 if ( ! is_array( $value ) && is_email( $value ) && wpf_is_field_active( $key ) && wpf_get_crm_field( $key ) == wpf_get_crm_field( 'user_email' ) ) {
  106.                     $update_data['user_email'] = $value;
  107.                 }
  108.             }
  109.         }
  110.  
  111.         // Possible additional event meta
  112.  
  113.         $event_meta = get_post_meta( $event_id );
  114.         if ( ! empty( $event_meta ) && is_array( $event_meta ) ) {
  115.             foreach ( $event_meta as $key => $value ) {
  116.  
  117.                 if ( 0 === strpos( $key, '_ecp_custom_' ) ) {
  118.                     $update_data[ $key ] = $value[0];
  119.                 }
  120.             }
  121.         }
  122.  
  123.         /**
  124.          * Filter the attendee data.
  125.          *
  126.          * @since 3.37.13
  127.          *
  128.          * @link  https://wpfusion.com/documentation/filters/wpf_event_tickets_attendee_data/
  129.          *
  130.          * @param array $update_data The attendee data to sync to the CRM.
  131.          * @param int   $attendee_id The attendee ID.
  132.          */
  133.  
  134.         $update_data = apply_filters( 'wpf_event_tickets_attendee_data', $update_data, $attendee_id );
  135.  
  136.         return $update_data;
  137.  
  138.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement