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 |
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"); var $custom_fields = array("Adult","Child"); // ADD "Label1, "Label2" var $seating_fields = array("seat_row_name"=>"Seating"); // ADD as "field"=>"label" - Added this line for 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); }// end __construct // 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) { foreach($this->fields as $field=>$label) $fields['ticket_standard_'.$field] = array( 'label' => $label, 'colname' => $label, 'checked' => 1 ); foreach($this->custom_fields as $label) $fields['ticket_custom_'.$label] = array( 'label' => $label, 'colname' => $label, 'checked' => 1 ); foreach($this->seating_fields as $field=>$label) //Added these 2 lines for seating $fields['ticket_seating_'.$field] = array( 'label' => $label, 'colname' => $label, 'checked' => 1 ); return $fields; } function fill_foo_fields($products,$order,$labels, $format, $static_vals) { $tickets_set = get_post_meta($order->id, "WooCommerceEventsOrderTickets", true); $this->line_id = 1; $results = array(); $pos = 0; $products = array_values($products); 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 $tickets) { foreach($tickets as $ticket) { // found assigned tickets?? if( $item['product_id'] AND !$item['variation_id'] AND ($ticket['WooCommerceEventsProductID'] == $item['product_id']) OR $item['variation_id'] AND ($ticket['WooCommerceEventsVariationID'] == $item['variation_id']) ) { $this->add_ticket($results, $ticket,$labels,$product_data); $found_ticket = true; } } } if( ! $found_ticket ) // not ticket, stay unchanaged! $results[] = $product_data; } return $results; } function add_ticket(&$results, $ticket,$labels,$product_data) { $WooCommerceEventsCustomAttendeeFields = array(); if(!empty($ticket['WooCommerceEventsCustomAttendeeFields'])) { if (is_plugin_active('fooevents_custom_attendee_fields/fooevents-custom-attendee-fields.php') || is_plugin_active_for_network('fooevents_custom_attendee_fields/fooevents-custom-attendee-fields.php')) { $Fooevents_Custom_Attendee_Fields = new Fooevents_Custom_Attendee_Fields(); $ticket_cust = $Fooevents_Custom_Attendee_Fields->fetch_attendee_details_for_order($ticket['WooCommerceEventsProductID'], $ticket['WooCommerceEventsCustomAttendeeFields']); foreach($ticket_cust as $key=>$data) $WooCommerceEventsCustomAttendeeFields[$data['field'][$key.'_label']] = $data["value"]; } } $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]]; } 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(); |