FooEvents For WooCommerce
You should EDIT and TWEAK code , see comments!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
//if you need Seating fields -- please, contact us and provide all necessary plugins! class WOE_FooTickets_As_Products { var $fields = array( "TicketType" => "Ticket Type", "Status" => "Ticket Status", "AttendeeName" => "Attendee First Name", "AttendeeLastName" => "Attendee Last Name", "AttendeeEmail" => "Attendee Email", "AttendeeTelephone" => "Attendee Phone", "AttendeeCompany" => "Attendee Company", "AttendeeDesignation" => "Attendee Designation", "PurchaserFirstName" => "Purchaser First Name", "PurchaserLastName" => "Purchaser Last Name", "PurchaserEmail" => "Purchaser Email", "BookingSlot"=>"Booking Slot", "BookingDate"=>"Booking Date", ); var $custom_fields = array( "Registration Type" => "Custom Registration Type", ); // var $seating_fields = array("seat_row_name" => "Seating"); function __construct() { add_action("woe_settings_above_buttons", array($this, "draw_options")); add_filter("woe_settings_validate_defaults", array($this, "modify_export"), 10, 1); add_filter('woe_get_order_product_fields', array($this, "add_product_fields"), 10, 1); } function draw_options($settings) { $selected = !empty($settings['fill_foo_fields']) ? 'checked' : ''; echo '<br><br> <input type=hidden name="settings[fill_foo_fields]" value="0"> <input type=checkbox name="settings[fill_foo_fields]" value="1" ' . $selected . '> <span class="wc-oe-header">Export Foo Events fields</span><br>'; } function modify_export($current_job_settings) { if (!empty($current_job_settings['fill_foo_fields'])) add_filter('woe_fetch_order_products', array($this, "fill_foo_fields"), 10, 5); return $current_job_settings; } function add_product_fields($fields) { $fields = [];// Alex - export only ticket fields foreach ($this->fields as $field => $label) $fields['ticket_standard_' . $field] = array('label' => $label, 'colname' => $label, 'checked' => 1); foreach ($this->custom_fields as $key=>$label) $fields['ticket_custom_' . $key] = array('label' => $label, 'colname' => $label, 'checked' => 1); //foreach ($this->seating_fields as $field => $label) // $fields['ticket_seating_' . $field] = array('label' => $label, 'colname' => $label, 'checked' => 1); return $fields; } function fill_foo_fields($products,$order,$labels, $format, $static_vals) { $tickets_query = new WP_Query( array( 'post_type' => array( 'event_magic_tickets' ), 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'WooCommerceEventsOrderID', 'value' => $order->get_id(), 'compare' => '=', ), ), ) ); $tickets = $tickets_query->get_posts(); $tickets_set = []; foreach($tickets as $ticket_obj){ $meta = get_post_meta($ticket_obj->ID); $tickets_set[$ticket_obj->ID] = $meta; } //$tickets_set = get_post_meta($order->id, "WooCommerceEventsOrderTickets", true); $this->line_id = 1; $results = array(); $pos = 0; $products = array_values($products); $tickets_exported = []; foreach ( $order->get_items('line_item') as $item_id=>$item ) { $found_ticket = false; // seek for assigned tickets $product_data = $products[$pos++]; // take already extracted data for product! foreach($tickets_set as $idx=>$ticket) { // found assigned tickets?? if( $item['product_id'] AND !$item['variation_id'] AND ($ticket['WooCommerceEventsProductID'][0] == $item['product_id']) OR $item['variation_id'] AND ($ticket['WooCommerceEventsVariationID'][0] == $item['variation_id']) ) { $found_ticket = true; // Alex - export only ticket fields $ticket_id = $ticket['WooCommerceEventsTicketID'][0]; if( in_array($ticket_id, $tickets_exported) ) continue; $tickets_exported[] = $ticket_id; $custom_fields = get_post_meta( $item['product_id'], 'fooevents_custom_attendee_fields_options_serialized', true ); if($custom_fields ) $custom_fields = json_decode($custom_fields, true); $this->add_ticket($results, $ticket,$labels,$product_data,$custom_fields); // var_dump($item_id, $ticket); die("xx"); // unset($tickets_set[$idx]);// use each ticket only ONCE! } } if( ! $found_ticket ) // not ticket, stay unchanged! $results[] = $product_data; } return $results; } function add_ticket(&$results, $ticket,$labels,$product_data,$custom_fields) { $WooCommerceEventsCustomAttendeeFields = array(); if(!empty($custom_fields)) { foreach($custom_fields as $key=>$data) $WooCommerceEventsCustomAttendeeFields[$data[$key.'_label']] = $ticket["fooevents_custom_" .$key][0]; } $row = array(); foreach ( $labels as $field => $label ) { if ( $field == 'line_id' ) { $row[ $field ] = $this->line_id++; } elseif ( preg_match('#ticket_standard_(.+)$#',$field,$m) ) { // FooEvents field $row[ $field ] = $ticket["WooCommerceEvents".$m[1]][0]; } elseif ( preg_match('#ticket_custom_(.+)$#',$field,$m) ) { // FooEvents custom field $row[ $field ] = isset($WooCommerceEventsCustomAttendeeFields[$m[1]]) ? $WooCommerceEventsCustomAttendeeFields[$m[1]] : ""; //} elseif ( preg_match('#ticket_seating_(.+)$#',$field,$m) ) { // FooEvents seating field // $row[ $field ] = str_replace('_', ' ',$ticket["WooCommerceEventsSeatingFields"]["fooevents_".$m[1]]); } elseif ( isset( $product_data[$field]) ) { // Item field ? $row[ $field ] = $product_data[$field]; } else $row[ $field ] = ''; } $results[] = $row; } } new WOE_FooTickets_As_Products(); |