function tc_get_order_event($field_name = '', $post_id = '') { $order_status = get_post_status($post_id); $order_status = $order_status == 'trash' ? 'trash' : 'publish'; $orders = new TC_Orders(); $user_id = get_current_user_id(); $order_id = get_the_title($post_id); $cart_contents = get_post_meta($post_id, 'tc_cart_contents', true); $cart_info = get_post_meta($post_id, 'tc_cart_info', true); $owner_data = isset($cart_info['owner_data']) ? $cart_info['owner_data'] : array(); $tickets = count($cart_contents); $args = array('posts_per_page' => -1, 'orderby' => 'post_date', 'order' => 'ASC', 'post_type' => 'tc_tickets_instances', 'post_status' => array('trash', 'publish'), 'post_parent' => $post_id); $tickets = get_posts($args); $columns = $orders->get_owner_info_fields(); $columns = apply_filters('tc_order_details_owner_columns', $columns); $style = ''; ?> <table class="order-details widefat shadow-table"> <tr> <?php foreach ($columns as $column) { ?> <th><?php echo $column['field_title']; ?> </th> <?php } ?> </tr> <?php foreach ($tickets as $ticket) { $style = ' class="alternate"' == $style ? '' : ' class="alternate"'; ?> <tr <?php echo $style; ?> > <?php foreach ($columns as $column) { ?> <td class="<?php echo esc_attr($column['field_name']); ?> " data-id="<?php echo $column['field_name'] == 'ID' ? $ticket->ID : ''; ?> "> <?php if ($column['field_type'] == 'function') { eval($column['function'] . '("' . $column['field_name'] . '", "' . (isset($column['field_id']) ? $column['field_id'] : '') . '", "' . $ticket->ID . '");'); } else { if ($column['post_field_type'] == 'post_meta') { $value = get_post_meta($ticket->ID, $column['field_name'], true); if (empty($value)) { echo '-'; } else { echo $value; } } if ($column['post_field_type'] == 'ID') { echo $ticket->ID; } } ?> </td> <?php } ?> </tr> <?php } ?> </table> <?php if (count($tickets) == 0 && count($cart_contents) > 0) { ?> <div class="tc_order_tickets_warning"> <?php _e('We can\'t find any ticket associated with this order. It seems that attendee info / ticket is deleted.', 'tc'); ?> </div> <?php } }
function tc_get_order_event($field_name = '', $post_id = '') { $order_status = get_post_status($post_id); $order_status = $order_status == 'trash' ? 'trash' : 'publish'; $orders = new TC_Orders(); $user_id = get_current_user_id(); $order_id = get_the_title($post_id); $cart_contents = get_post_meta($post_id, 'tc_cart_contents', true); $cart_info = get_post_meta($post_id, 'tc_cart_info', true); $owner_data = $cart_info['owner_data']; $tickets = count($cart_contents); if (isset($_POST['recreate_tickets'])) { //recreating tickets //Save Ticket Owner(s) data //$owner_data = $_SESSION[ 'cart_info' ][ 'owner_data' ]; $owner_records = array(); $different_ticket_types = array_keys($owner_data['ticket_type_id_post_meta']); $n = 0; $i = 1; foreach ($different_ticket_types as $different_ticket_type) { $i = $i + 10; foreach ($owner_data as $field_name => $field_values) { $inner_count = count($field_values[$different_ticket_type]); foreach ($field_values[$different_ticket_type] as $field_value) { $owner_records[((int) $n + (int) $inner_count) * (int) $i][$field_name] = $field_value; $inner_count = $inner_count + 1; } } $n = $n++; } $owner_record_num = 1; foreach ($owner_records as $owner_record) { foreach ($owner_record as $owner_field_name => $owner_field_value) { if (preg_match('/_post_title/', $owner_field_name)) { $title = $owner_field_value; } if (preg_match('/_post_excerpt/', $owner_field_name)) { $excerpt = $owner_field_value; } if (preg_match('/_post_content/', $owner_field_name)) { $content = $owner_field_value; } if (preg_match('/_post_meta/', $owner_field_name)) { $metas[str_replace('_post_meta', '', $owner_field_name)] = $owner_field_value; } } $metas['ticket_code'] = apply_filters('tc_ticket_code', $order_id . '-' . $owner_record_num); $arg = array('post_author' => isset($user_id) ? $user_id : '', 'post_parent' => $post_id, 'post_excerpt' => isset($excerpt) ? $excerpt : '', 'post_content' => isset($content) ? $content : '', 'post_status' => $order_status, 'post_title' => isset($title) ? $title : '', 'post_type' => 'tc_tickets_instances'); $owner_record_id = @wp_insert_post($arg, true); foreach ($metas as $meta_name => $mata_value) { update_post_meta($owner_record_id, $meta_name, $mata_value); } $ticket_type_id = get_post_meta($owner_record_id, 'ticket_type_id', true); $ticket_type = new TC_Ticket($ticket_type_id); $event_id = $ticket_type->get_ticket_event(); update_post_meta($owner_record_id, 'event_id', $event_id); $owner_record_num++; } } //END recreating tickets $args = array('posts_per_page' => -1, 'orderby' => 'post_date', 'order' => 'ASC', 'post_type' => 'tc_tickets_instances', 'post_status' => array('trash', 'publish'), 'post_parent' => $post_id); $tickets = get_posts($args); $columns = $orders->get_owner_info_fields(); $columns = apply_filters('tc_order_details_owner_columns', $columns); $style = ''; ?> <table class="order-details widefat shadow-table"> <tr> <?php foreach ($columns as $column) { ?> <th><?php echo $column['field_title']; ?> </th> <?php } ?> </tr> <?php foreach ($tickets as $ticket) { $style = ' class="alternate"' == $style ? '' : ' class="alternate"'; ?> <tr <?php echo $style; ?> > <?php foreach ($columns as $column) { ?> <td class="<?php echo esc_attr($column['field_name']); ?> " data-id="<?php echo $column['field_name'] == 'ID' ? $ticket->ID : ''; ?> "> <?php if ($column['field_type'] == 'function') { eval($column['function'] . '("' . $column['field_name'] . '", "' . (isset($column['field_id']) ? $column['field_id'] : '') . '", "' . $ticket->ID . '");'); } else { if ($column['post_field_type'] == 'post_meta') { $value = get_post_meta($ticket->ID, $column['field_name'], true); if (empty($value)) { echo '-'; } else { echo $value; } } if ($column['post_field_type'] == 'ID') { echo $ticket->ID; } } ?> </td> <?php } ?> </tr> <?php } ?> </table> <?php if (count($tickets) == 0 && count($cart_contents) > 0) { ?> <div class="status_red tc_order_tickets_warning"> <?php _e('There are not any tickets. Would you like to try to recreate them? ', 'tc'); ?> <form name="tc_recreate_tickets" method="POST"> <input type="submit" name="recreate_tickets" value="<?php echo esc_attr(__('Recrete Tickets', 'tc')); ?> " /> </form> </div> <?php } }