Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function add_attendee_data( $order_id, $contact_id ) {
- $order = wc_get_order( $order_id );
- foreach ( $this->get_attendees_from_order( $order ) as $attendee ) {
- $settings = get_post_meta( $attendee['WooCommerceEventsProductID'], 'wpf-settings-woo', true );
- if ( empty( $settings ) || ! isset( $settings['add_attendees'] ) || $settings['add_attendees'] != true ) {
- continue;
- }
- // This was already sent in the main order data so it doesn't need to be sent again
- if ( $attendee['WooCommerceEventsAttendeeEmail'] == $order->get_billing_email() ) {
- continue;
- }
- if ( empty( $attendee['WooCommerceEventsAttendeeEmail'] ) ) {
- wpf_log( 'notice', 0, 'Unable to sync attendee data, no email address provided. To sync attendees you must enable <strong>Capture attendee full name and email address?</strong> when editing the FooEvent product.' );
- continue;
- }
- $update_data = array(
- 'first_name' => $attendee['WooCommerceEventsAttendeeName'],
- 'attendee_first_name' => $attendee['WooCommerceEventsAttendeeName'],
- 'last_name' => $attendee['WooCommerceEventsAttendeeLastName'],
- 'attendee_last_name' => $attendee['WooCommerceEventsAttendeeLastName'],
- 'user_email' => $attendee['WooCommerceEventsAttendeeEmail'],
- 'attendee_email' => $attendee['WooCommerceEventsAttendeeEmail'],
- 'billing_phone' => $attendee['WooCommerceEventsAttendeeTelephone'],
- 'phone_number' => $attendee['WooCommerceEventsAttendeeTelephone'],
- 'attendee_phone' => $attendee['WooCommerceEventsAttendeeTelephone'],
- 'billing_company' => $attendee['WooCommerceEventsAttendeeCompany'],
- 'company' => $attendee['WooCommerceEventsAttendeeCompany'],
- 'attendee_company' => $attendee['WooCommerceEventsAttendeeCompany'],
- 'attendee_designation' => $attendee['WooCommerceEventsAttendeeDesignation'],
- );
- // Merge event and venue fields
- $product_id = $attendee['WooCommerceEventsProductID'];
- $hour = get_post_meta( $product_id, 'WooCommerceEventsHour', true );
- $minutes = get_post_meta( $product_id, 'WooCommerceEventsMinutes', true );
- $period = get_post_meta( $product_id, 'WooCommerceEventsPeriod', true );
- $event_fields = array(
- 'event_name' => get_the_title( $product_id ),
- 'event_start_date' => get_post_meta( $product_id, 'WooCommerceEventsDate', true ),
- 'event_start_time' => $hour . ':' . $minutes . ' ' . $period,
- 'event_venue_name' => get_post_meta( $product_id, 'WooCommerceEventsLocation', true ),
- 'zoom_meeting_id' => get_post_meta( $product_id, 'WooCommerceEventsZoomWebinar', true ),
- 'zoom_join_url' => get_post_meta( $product_id, 'wp_fusion_zoom_join_url', true ),
- );
- // Zoom.
- if ( ! empty( $event_fields['zoom_meeting_id'] ) && empty( $event_fields['zoom_join_url'] ) && wpf_is_field_active( 'zoom_join_url' ) && class_exists( 'FooEvents_Zoom_API_Helper' ) ) {
- // The Zoom integration currently doesn't cache the meeting URL in the database so we'll fetch it one time here.
- $helper = new FooEvents_Zoom_API_Helper();
- $result = $helper->do_fooevents_fetch_zoom_meeting( $event_fields['zoom_meeting_id'] );
- if ( ! empty( $result['status'] ) && 'success' === $result['status'] ) {
- $event_fields['zoom_join_url'] = $result['data']['join_url'];
- update_post_meta( $product_id, 'wp_fusion_zoom_join_url', $event_fields['zoom_join_url'] );
- }
- }
- // Bookings extension.
- if ( ! empty( $attendee['WooCommerceEventsBookingOptions'] ) ) {
- $slot = $attendee['WooCommerceEventsBookingOptions']['slot'];
- $date = $attendee['WooCommerceEventsBookingOptions']['date'];
- $booking_options = get_post_meta( $product_id, 'fooevents_bookings_options_serialized', true );
- $booking_options = json_decode( $booking_options, true );
- if ( ! empty( $booking_options ) && isset( $booking_options[ $slot ] ) ) {
- $time = trim( $booking_options[ $slot ]['formatted_time'], '()' );
- $date = $booking_options[ $slot ]['add_date'][ $date ]['date'];
- $event_fields['booking_date'] = $date . ' ' . $time;
- $event_fields['booking_time'] = $time;
- }
- }
- $update_data = array_merge( $update_data, $event_fields );
- // Merge custom fields
- if ( ! empty( $attendee['WooCommerceEventsCustomAttendeeFields'] ) ) {
- // New v5.5+ method
- $update_data = array_merge( $update_data, $attendee['WooCommerceEventsCustomAttendeeFields'] );
- // Old method:
- foreach ( $attendee['WooCommerceEventsCustomAttendeeFields'] as $key => $value ) {
- $key = strtolower( str_replace( 'fooevents_custom_', '', $key ) );
- $update_data[ $key ] = $value;
- }
- }
- $update_data = apply_filters( 'wpf_woocommerce_attendee_data', $update_data, $attendee, $order_id );
- $contact_id = wp_fusion()->crm->get_contact_id( $update_data['user_email'] );
- wpf_log( 'info', 0, 'FooEvents adding new event attendee for order <a href="' . admin_url( 'post.php?post=' . $order_id . '&action=edit' ) . '" target="_blank">#' . $order_id . '</a>:', array( 'meta_array' => $update_data ) );
- if ( empty( $contact_id ) ) {
- $contact_id = wp_fusion()->crm->add_contact( $update_data );
- } else {
- wp_fusion()->crm->update_contact( $contact_id, $update_data );
- }
- $apply_tags = array();
- // Product settings
- if ( ! empty( $settings['apply_tags_event_attendees'] ) ) {
- $apply_tags = array_merge( $apply_tags, $settings['apply_tags_event_attendees'] );
- }
- // Variation settings
- if ( ! empty( $attendee['WooCommerceEventsVariationID'] ) ) {
- $settings = get_post_meta( $attendee['WooCommerceEventsVariationID'], 'wpf-settings-woo', true );
- if ( ! empty( $settings ) && ! empty( $settings['apply_tags_event_attendees_variation'] ) && ! empty( $settings['apply_tags_event_attendees_variation'][ $attendee['WooCommerceEventsVariationID'] ] ) ) {
- $apply_tags = array_merge( $apply_tags, $settings['apply_tags_event_attendees_variation'][ $attendee['WooCommerceEventsVariationID'] ] );
- }
- }
- if ( ! empty( $apply_tags ) ) {
- wpf_log( 'info', 0, 'Applying tags to FooEvents attendee for contact ID ' . $contact_id . ': ', array( 'tag_array' => $apply_tags ) );
- wp_fusion()->crm->apply_tags( $apply_tags, $contact_id );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement