Tickera
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 |
add_filter('woe_get_order_product_fields',function ($fields) { $fields['event_name'] = array('label'=>'Event Name','colname'=>'Event Name','checked'=>1); $fields['event_start_at'] = array('label'=>'Event Start','colname'=>'Event Start','checked'=>1); $fields['event_end_at'] = array('label'=>'Event End','colname'=>'Event End','checked'=>1); $fields['event_location'] = array('label'=>'Event Location','colname'=>'Event Location','checked'=>1); $fields['ticket_type'] = array('label'=>'Ticket Type','colname'=>'Ticket Type','checked'=>1); $fields['ticket_owner'] = array('label'=>'Ticket Owner Name','colname'=>'Ticket Owner Name','checked'=>1); $fields['ticket_owner_first'] = array('label'=>'Ticket Owner First Name','colname'=>'Ticket Owner First Name','checked'=>1); $fields['ticket_owner_last'] = array('label'=>'Ticket Owner Last Name','colname'=>'Ticket Owner Last Name','checked'=>1); $fields['ticket_email'] = array('label'=>'Ticket Owner Email','colname'=>'Ticket Owner Email','checked'=>1); $fields['ticket_code'] = array('label'=>'Ticket Code','colname'=>'Ticket Code','checked'=>1); // get form fields $args = array( 'post_type' => 'tc_form_fields', 'post_status' => 'publish', 'posts_per_page' => -1, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false, 'fields' => array( 'ID', 'post_parent' ), ); $custom_fields = get_posts( $args ); if ( count( $custom_fields ) > 0 ) { foreach ( $custom_fields as $custom_field ) { $form_status = get_post_status( $custom_field->post_parent ); $form_title = get_the_title( $custom_field->post_parent ); if ( $form_status == 'publish' ) { $element_class_name = get_post_meta( $custom_field->ID, 'field_type', true ); $form_type = get_post_meta( $custom_field->post_parent, 'form_type', true ); if ( class_exists( $element_class_name ) ) { $element = new $element_class_name( $custom_field->ID ); if ( $element->standard_field_export( $element->element_name, true ) ) { $field = $element->admin_order_details_page_value(); // add new field $fields['ticket_CF_' . $field['id'] ] = array('label'=>"[$form_title] " . $field['field_title'],'colname'=>"[$form_title] " . $field['field_title'],'checked'=>1); }// if can be exported }// } } // if visible } // if fields return $fields; }); add_filter('woe_fetch_order_products', function ($data, $order, $labels, $format, $static_vals ) { $ticket_field_names = array("event_name","event_start_at","event_end_at","event_location","ticket_type","ticket_owner","ticket_email","ticket_code"); $first_row = array_shift(array_values($data)); //run only if Tickera fields was added to export $has_ticket_columns = false; foreach($first_row as $key=>$value) { if( in_array($key,$ticket_field_names) OR preg_match('#^ticket_CF_(.+)$#',$key,$field_key) ) { $has_ticket_columns = true; break; } } if( !$has_ticket_columns ) return $data; $new_data = array(); $used_keys = array(); $args = array( 'posts_per_page' => -1, 'orderby' => 'post_date', 'order' => 'ASC', 'post_type' => 'tc_tickets_instances', 'post_parent' => $order->get_id(), ); $tickets = get_posts($args); foreach($tickets as $pos=>$ticket) { //fill ticket data $ticket_type_id = get_post_meta($ticket->ID, 'ticket_type_id', true);// it's a product_id !!! if( $ticket_type_id ) { $ticket_type = new Tickera\TC_Ticket($ticket_type_id); if( $ticket_type ) { // must find Item ID of main product foreach($order->get_items() as $item_id=>$item) { if( $item['product_id'] == $ticket_type_id OR $item['variation_id'] AND $item['variation_id'] == $ticket_type_id) { $new_row = $data[$item_id]; $used_keys[] = $item_id; break; } } $event_id = $ticket_type->get_ticket_event(); $event = get_post($event_id, ARRAY_A); //gather details $t_data = array(); $t_data['event_name'] = $event['post_title']; $t_data['event_start_at'] = get_post_meta( $event_id , 'event_date_time', true); $t_data['event_end_at'] = get_post_meta( $event_id , 'event_end_date_time', true); $t_data['event_location'] = get_post_meta( $event_id , 'event_location', true); $t_data['ticket_type'] = $ticket_type->details->post_title; $t_data['ticket_owner'] = get_post_meta($ticket->ID, 'first_name', true) ." " .get_post_meta($ticket->ID, 'last_name', true); $t_data['ticket_owner_first'] = get_post_meta($ticket->ID, 'first_name', true); $t_data['ticket_owner_last'] = get_post_meta($ticket->ID, 'last_name', true); $t_data['ticket_email'] = get_post_meta($ticket->ID, 'owner_email', true); $t_data['ticket_code'] = get_post_meta($ticket->ID, 'ticket_code', true); //fill only selected Tickera fields foreach($t_data as $key=>$value) if( isset($first_row[$key])) $new_row[$key] = $value; // try to get Custom Form fields foreach($first_row as $key=>$value) { if( preg_match('#^ticket_CF_(.+)$#',$key,$field_key) ) $new_row[$key] = get_post_meta($ticket->ID, $field_key[1], true); } //done! $new_data[] = $new_row; } } } // export items which have NO tickets! foreach($data as $key=>$row) if( !in_array($key, $used_keys) ) $new_data[] = $row; return $new_data; },10,5); |