Advertisement
verygoodplugins

Untitled

Aug 25th, 2021
1,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.37 KB | None | 0 0
  1.     public function add_attendee_data( $order_id, $contact_id ) {
  2.  
  3.         $order = wc_get_order( $order_id );
  4.  
  5.         foreach ( $this->get_attendees_from_order( $order ) as $attendee ) {
  6.  
  7.             $settings = get_post_meta( $attendee['WooCommerceEventsProductID'], 'wpf-settings-woo', true );
  8.  
  9.             if ( empty( $settings ) || ! isset( $settings['add_attendees'] ) || $settings['add_attendees'] != true ) {
  10.                 continue;
  11.             }
  12.  
  13.             // This was already sent in the main order data so it doesn't need to be sent again
  14.  
  15.             if ( $attendee['WooCommerceEventsAttendeeEmail'] == $order->get_billing_email() ) {
  16.                 continue;
  17.             }
  18.  
  19.             if ( empty( $attendee['WooCommerceEventsAttendeeEmail'] ) ) {
  20.                 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.' );
  21.                 continue;
  22.             }
  23.  
  24.             $update_data = array(
  25.                 'first_name'           => $attendee['WooCommerceEventsAttendeeName'],
  26.                 'attendee_first_name'  => $attendee['WooCommerceEventsAttendeeName'],
  27.                 'last_name'            => $attendee['WooCommerceEventsAttendeeLastName'],
  28.                 'attendee_last_name'   => $attendee['WooCommerceEventsAttendeeLastName'],
  29.                 'user_email'           => $attendee['WooCommerceEventsAttendeeEmail'],
  30.                 'attendee_email'       => $attendee['WooCommerceEventsAttendeeEmail'],
  31.                 'billing_phone'        => $attendee['WooCommerceEventsAttendeeTelephone'],
  32.                 'phone_number'         => $attendee['WooCommerceEventsAttendeeTelephone'],
  33.                 'attendee_phone'       => $attendee['WooCommerceEventsAttendeeTelephone'],
  34.                 'billing_company'      => $attendee['WooCommerceEventsAttendeeCompany'],
  35.                 'company'              => $attendee['WooCommerceEventsAttendeeCompany'],
  36.                 'attendee_company'     => $attendee['WooCommerceEventsAttendeeCompany'],
  37.                 'attendee_designation' => $attendee['WooCommerceEventsAttendeeDesignation'],
  38.             );
  39.  
  40.             // Merge event and venue fields
  41.             $product_id = $attendee['WooCommerceEventsProductID'];
  42.  
  43.             $hour    = get_post_meta( $product_id, 'WooCommerceEventsHour', true );
  44.             $minutes = get_post_meta( $product_id, 'WooCommerceEventsMinutes', true );
  45.             $period  = get_post_meta( $product_id, 'WooCommerceEventsPeriod', true );
  46.  
  47.             $event_fields = array(
  48.                 'event_name'       => get_the_title( $product_id ),
  49.                 'event_start_date' => get_post_meta( $product_id, 'WooCommerceEventsDate', true ),
  50.                 'event_start_time' => $hour . ':' . $minutes . ' ' . $period,
  51.                 'event_venue_name' => get_post_meta( $product_id, 'WooCommerceEventsLocation', true ),
  52.                 'zoom_meeting_id'  => get_post_meta( $product_id, 'WooCommerceEventsZoomWebinar', true ),
  53.                 'zoom_join_url'    => get_post_meta( $product_id, 'wp_fusion_zoom_join_url', true ),
  54.             );
  55.  
  56.             // Zoom.
  57.  
  58.             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' ) ) {
  59.  
  60.                 // The Zoom integration currently doesn't cache the meeting URL in the database so we'll fetch it one time here.
  61.  
  62.                 $helper = new FooEvents_Zoom_API_Helper();
  63.                 $result = $helper->do_fooevents_fetch_zoom_meeting( $event_fields['zoom_meeting_id'] );
  64.  
  65.                 if ( ! empty( $result['status'] ) && 'success' === $result['status'] ) {
  66.                     $event_fields['zoom_join_url'] = $result['data']['join_url'];
  67.                     update_post_meta( $product_id, 'wp_fusion_zoom_join_url', $event_fields['zoom_join_url'] );
  68.                 }
  69.             }
  70.  
  71.             // Bookings extension.
  72.  
  73.             if ( ! empty( $attendee['WooCommerceEventsBookingOptions'] ) ) {
  74.  
  75.                 $slot = $attendee['WooCommerceEventsBookingOptions']['slot'];
  76.                 $date = $attendee['WooCommerceEventsBookingOptions']['date'];
  77.  
  78.                 $booking_options = get_post_meta( $product_id, 'fooevents_bookings_options_serialized', true );
  79.                 $booking_options = json_decode( $booking_options, true );
  80.  
  81.                 if ( ! empty( $booking_options ) && isset( $booking_options[ $slot ] ) ) {
  82.  
  83.                     $time = trim( $booking_options[ $slot ]['formatted_time'], '()' );
  84.                     $date = $booking_options[ $slot ]['add_date'][ $date ]['date'];
  85.  
  86.                     $event_fields['booking_date'] = $date . ' ' . $time;
  87.                     $event_fields['booking_time'] = $time;
  88.  
  89.                 }
  90.             }
  91.  
  92.             $update_data = array_merge( $update_data, $event_fields );
  93.  
  94.             // Merge custom fields
  95.             if ( ! empty( $attendee['WooCommerceEventsCustomAttendeeFields'] ) ) {
  96.  
  97.                 // New v5.5+ method
  98.  
  99.                 $update_data = array_merge( $update_data, $attendee['WooCommerceEventsCustomAttendeeFields'] );
  100.  
  101.                 // Old method:
  102.  
  103.                 foreach ( $attendee['WooCommerceEventsCustomAttendeeFields'] as $key => $value ) {
  104.  
  105.                     $key = strtolower( str_replace( 'fooevents_custom_', '', $key ) );
  106.  
  107.                     $update_data[ $key ] = $value;
  108.  
  109.                 }
  110.             }
  111.  
  112.             $update_data = apply_filters( 'wpf_woocommerce_attendee_data', $update_data, $attendee, $order_id );
  113.  
  114.             $contact_id = wp_fusion()->crm->get_contact_id( $update_data['user_email'] );
  115.  
  116.             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 ) );
  117.  
  118.             if ( empty( $contact_id ) ) {
  119.  
  120.                 $contact_id = wp_fusion()->crm->add_contact( $update_data );
  121.  
  122.             } else {
  123.  
  124.                 wp_fusion()->crm->update_contact( $contact_id, $update_data );
  125.  
  126.             }
  127.  
  128.             $apply_tags = array();
  129.  
  130.             // Product settings
  131.  
  132.             if ( ! empty( $settings['apply_tags_event_attendees'] ) ) {
  133.                 $apply_tags = array_merge( $apply_tags, $settings['apply_tags_event_attendees'] );
  134.             }
  135.  
  136.             // Variation settings
  137.  
  138.             if ( ! empty( $attendee['WooCommerceEventsVariationID'] ) ) {
  139.  
  140.                 $settings = get_post_meta( $attendee['WooCommerceEventsVariationID'], 'wpf-settings-woo', true );
  141.  
  142.                 if ( ! empty( $settings ) && ! empty( $settings['apply_tags_event_attendees_variation'] ) && ! empty( $settings['apply_tags_event_attendees_variation'][ $attendee['WooCommerceEventsVariationID'] ] ) ) {
  143.                     $apply_tags = array_merge( $apply_tags, $settings['apply_tags_event_attendees_variation'][ $attendee['WooCommerceEventsVariationID'] ] );
  144.                 }
  145.             }
  146.  
  147.             if ( ! empty( $apply_tags ) ) {
  148.  
  149.                 wpf_log( 'info', 0, 'Applying tags to FooEvents attendee for contact ID ' . $contact_id . ': ', array( 'tag_array' => $apply_tags ) );
  150.  
  151.                 wp_fusion()->crm->apply_tags( $apply_tags, $contact_id );
  152.  
  153.             }
  154.         }
  155.  
  156.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement