Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Gets all the attendee and event meta from an attendee ID.
- *
- * @param Int $attendee_id The attendee ID.
- * @return array The data to sync to the CRM.
- */
- public function get_attendee_meta( $attendee_id ) {
- // Get the event ID (Tribe annoyingly stores these all in different keys)
- $event_id = get_post_meta( $attendee_id, '_tribe_wooticket_event', true );
- $ticket_id = get_post_meta( $attendee_id, '_tribe_wooticket_product', true );
- if ( empty( $event_id ) ) {
- $event_id = get_post_meta( $attendee_id, '_tribe_eddticket_event', true );
- $ticket_id = get_post_meta( $attendee_id, '_tribe_eddticket_product', true );
- }
- if ( empty( $event_id ) ) {
- $event_id = get_post_meta( $attendee_id, '_tribe_rsvp_event', true );
- $ticket_id = get_post_meta( $attendee_id, '_tribe_rsvp_product', true );
- }
- // This is a bit tricky. When Allow Individual Attendee Collection is off, this will be the purchaser's
- // email. Also if it's on, but left blank.
- $attendee_email = get_post_meta( $attendee_id, '_tribe_tickets_email', true );
- if ( empty( $attendee_email ) ) {
- $attendee_email = get_post_meta( $attendee_id, '_tribe_rsvp_email', true );
- }
- $venue_id = get_post_meta( $event_id, '_EventVenueID', true );
- $event_date = get_post_meta( $event_id, '_EventStartDate', true );
- $event_address = get_post_meta( $venue_id, '_VenueAddress', true );
- $event_city = get_post_meta( $venue_id, '_VenueCity', true );
- $event_country = get_post_meta( $venue_id, '_VenueCountry', true );
- $event_state = get_post_meta( $venue_id, '_VenueState', true );
- $event_province = get_post_meta( $venue_id, '_VenueProvince', true );
- $event_zip = get_post_meta( $venue_id, '_VenueZip', true );
- $event_time = date( 'g:ia', strtotime( $event_date ) );
- $update_data = array(
- 'user_email' => $attendee_email,
- 'ticket_name' => get_the_title( $ticket_id ),
- 'event_name' => get_the_title( $event_id ),
- 'event_date' => $event_date,
- 'event_time' => $event_time,
- 'venue_name' => get_the_title( $venue_id ),
- 'event_address' => $event_address,
- 'event_city' => $event_city,
- 'event_state' => $event_state,
- 'event_province' => $event_province,
- 'event_country' => $event_country,
- 'event_zip' => $event_zip,
- );
- // Name
- $full_name = get_post_meta( $attendee_id, '_tribe_tickets_full_name', true );
- if ( empty( $full_name ) ) {
- $full_name = get_post_meta( $attendee_id, '_tribe_rsvp_full_name', true );
- }
- if ( ! empty( $full_name ) ) {
- $parts = explode( ' ', $full_name, 2 );
- $update_data['first_name'] = $parts[0];
- if ( isset( $parts[1] ) ) {
- $update_data['last_name'] = $parts[1];
- }
- }
- // Organizer
- $organizer_id = get_post_meta( $event_id, '_EventOrganizerID', true );
- if ( ! empty( $organizer_id ) ) {
- $organizer_data = array(
- 'organizer_name' => get_the_title( $organizer_id ),
- 'organizer_phone' => get_post_meta( $organizer_id, '_OrganizerPhone', true ),
- 'organizer_website' => get_post_meta( $organizer_id, '_OrganizerWebsite', true ),
- 'organizer_email' => get_post_meta( $organizer_id, '_OrganizerEmail', true ),
- );
- $update_data = array_merge( $update_data, $organizer_data );
- }
- $ticket_meta = get_post_meta( $attendee_id, '_tribe_tickets_meta', true );
- if ( ! empty( $ticket_meta ) ) {
- $update_data = array_merge( $update_data, $ticket_meta );
- // Cases where a custom email field needs to take priority over the standard email field
- foreach ( $ticket_meta as $key => $value ) {
- if ( ! is_array( $value ) && is_email( $value ) && wpf_is_field_active( $key ) && wpf_get_crm_field( $key ) == wpf_get_crm_field( 'user_email' ) ) {
- $update_data['user_email'] = $value;
- }
- }
- }
- // Possible additional event meta
- $event_meta = get_post_meta( $event_id );
- if ( ! empty( $event_meta ) && is_array( $event_meta ) ) {
- foreach ( $event_meta as $key => $value ) {
- if ( 0 === strpos( $key, '_ecp_custom_' ) ) {
- $update_data[ $key ] = $value[0];
- }
- }
- }
- /**
- * Filter the attendee data.
- *
- * @since 3.37.13
- *
- * @link https://wpfusion.com/documentation/filters/wpf_event_tickets_attendee_data/
- *
- * @param array $update_data The attendee data to sync to the CRM.
- * @param int $attendee_id The attendee ID.
- */
- $update_data = apply_filters( 'wpf_event_tickets_attendee_data', $update_data, $attendee_id );
- return $update_data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement