Title: [Plugin: Woocommerce booking plugin]
Last modified: August 22, 2016

---

# [Plugin: Woocommerce booking plugin]

 *  [Robinhol](https://wordpress.org/support/users/robinhol/)
 * (@robinhol)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/plugin-woocommerce-booking-plugin/)
 * Im using a plugin called woocommerce booking plugin by tychesoftwares.
 * I have added a custom checkout field where the customer can insert the name of
   the attendee of a course. This field is save to the wp_metapost with my own defined
   meta_key.
 * On the admin page of this plugin there is a page called “View bookings”.
    I would
   like to display my custom field on this page. I know what function i need to 
   edit but I cannot get my custom mysql query to work. Can someone please show 
   me how to do the mysql query correct?
 * Part of the function:
 *     ```
       function woocommerce_history_page() {
   
       				if (isset($_GET['action']))
       				{
       					$action = $_GET['action'];
       				}
       				else
       				{
       					$action = '';
       				}
       				if ($action == 'history' || $action == '')
       				{
       					$active_settings = "nav-tab-active";
       				}
   
       				?>
   
       				<p></p>
   
       				<!-- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
       				<a href="admin.php?page=woocommerce_history_page&action=history" class="nav-tab <?php echo $active_settings; ?>"> <?php _e( 'Booking History', 'woocommerce-ac' );?> </a>
       				</h2> -->
   
       				<?php
   
       				if ( $action == 'history' || $action == '' )
       				{
       					global $wpdb;
   
       					$query_order = "SELECT DISTINCT order_id FROM <code>&quot; . $wpdb->prefix . &quot;woocommerce_order_items</code>  ";
       					$order_results = $wpdb->get_results( $query_order );
   
       					$var = $today_checkin_var = $today_checkout_var = $booking_time = "";
   
       					$booking_time_label = get_option('book.item-meta-time');
       				//	echo $booking_time_label;
   
       					foreach ( $order_results as $id_key => $id_value )
       					{
       						$order = new WC_Order( $id_value->order_id );
   
       						$order_items = $order->get_items();
   
       						$terms = wp_get_object_terms( $id_value->order_id, 'shop_order_status', array('fields' => 'slugs') );
       						if( (isset($terms[0]) && $terms[0] != 'cancelled') && (isset($terms[0]) && $terms[0] != 'refunded'))
       						{
       						$today_query = "SELECT * FROM <code>&quot;.$wpdb->prefix.&quot;booking_history</code> AS a1,<code>&quot;.$wpdb->prefix.&quot;booking_order_history</code> AS a2 WHERE a1.id = a2.booking_id AND a2.order_id = '".$id_value->order_id."'";
       						$results_date = $wpdb->get_results ( $today_query );
   
       						$c = 0;
       						foreach ($order_items as $items_key => $items_value )
       						{
       							$start_date = $end_date = $booking_time = "";
   
       							$booking_time = array();
       							//print_r($items_value);
       							if (isset($items_value[$booking_time_label]))
       							{
       								$booking_time = explode(",",$items_value[$booking_time_label]);
       							}
   
       							$duplicate_of = get_post_meta($items_value['product_id'], '_icl_lang_duplicate_of', true);
       							if($duplicate_of == '' && $duplicate_of == null)
       							{
       								$post_time = get_post($items_value['product_id']);
       								if (isset($post_time))
       								{
       									$id_query = "SELECT ID FROM <code>&quot;.$wpdb->prefix.&quot;posts</code> WHERE post_date = '".$post_time->post_date."' ORDER BY ID LIMIT 1";
       									$results_post_id = $wpdb->get_results ( $id_query );
       									if( isset($results_post_id) ) {
       										$duplicate_of = $results_post_id[0]->ID;
       									}
       									else
       									{
       										$duplicate_of = $items_value['product_id'];
       									}
       								}
       								else {
       									$duplicate_of = $items_value['product_id'];
       								}
       							}
       						//	echo "<pre>";echo $id_value->order_id; print_r($booking_time);echo "</pre>";
       							if ( isset($results_date[$c]->start_date) )
       							{
       								if (isset($results_date[$c]) && isset($results_date[$c]->start_date)) $start_date = $results_date[$c]->start_date;
   
       								if (isset($results_date[$c]) && isset($results_date[$c]->end_date)) $end_date = $results_date[$c]->end_date;
   
       								if ($start_date == '0000-00-00' || $start_date == '1970-01-01') $start_date = '';
       								if ($end_date == '0000-00-00' || $end_date == '1970-01-01') $end_date = '';
       								$amount = $items_value['line_total'] + $items_value['line_tax'];
       								if(is_plugin_active('bkap-printable-tickets/printable-tickets.php'))
       								{
       									$var_details = apply_filters('bkap_view_bookings',$id_value->order_id,$results_date[$c]->booking_id,$items_value['qty']);
       								}
       								else
       								{
       									$var_details = array();
       								}
       								if (count($booking_time) > 0)
       								{
       								foreach ($booking_time as $time_key => $time_value)
       								{
       									if(array_key_exists('ticket_id',$var_details) && array_key_exists('security_code',$var_details))
       									{
   
       										$var .= "<tr>
       										<td>".$id_value->order_id."</td>
       										<td>".$order->billing_first_name." ".$order->billing_last_name."</td>
       <td>".$results."</td>
   
       										<td>".$items_value['name']."</td>
       										<td>".$start_date."</td>
       										<td>".$end_date."</td>
       										<td>".$time_value."</td>
       										<td>".$amount."</td>
       										<td>".$order->completed_date."</td>
       										".$var_details['ticket_id']."
       										".$var_details['security_code']."
       										<td><a href=\"post.php?post=". $id_value->order_id."&action=edit\">View Order</a></td>
       										</tr>";
       									}
       									else
       									{
       										$var .= "<tr>
       										<td>".$id_value->order_id."</td>
       										<td>".$order->billing_first_name." ".$order->billing_last_name."</td>
       <td>".$results."</td>
       										<td>".$items_value['name']."</td>
       										<td>".$start_date."</td>
       										<td>".$end_date."</td>
       										<td>".$time_value."</td>
       										<td>".$amount."</td>
       										<td>".$order->completed_date."</td>
       										<td><a href=\"post.php?post=". $id_value->order_id."&action=edit\">View Order</a></td>
       										</tr>";
       									}
       									//foreach ($results_date as $key_date => $value_date )
       									{
       										/*$start_date_r = $end_date_r = '';
       										if (isset($value_date->start_date)) $start_date_r = $value_date->start_date;
       										if (isset($value_date->end_date)) $end_date_r = $value_date->end_date;
   
       										if ($start_date_r == '0000-00-00' || $start_date_r == '1970-01-01') $start_date_r = '';
       										if ($end_date_r == '0000-00-00' || $end_date_r == '1970-01-01') $end_date_r = '';*/
   
       										if ( $start_date == date('Y-m-d' , current_time('timestamp') ) )
       										{
       										if(array_key_exists('ticket_id',$var_details) && array_key_exists('security_code',$var_details))
   
       											{
       												$today_checkin_var .= "<tr>
       												<td>".$id_value->order_id."</td>
       												<td>".$order->billing_first_name." ".$order->billing_last_name."</td>
       <td>".$results."</td>
       												<td>".$items_value['name']."</td>
       												<td>".$start_date."</td>
       												<td>".$end_date."</td>
       												<td>".$time_value."</td>
       												<td>".$amount."</td>
       												<td>".$order->completed_date."</td>
       												".$var_details['ticket_id']."
       												".$var_details['security_code']."
       												<td><a href=\"post.php?post=". $id_value->order_id."&action=edit\">View Order</a></td>
       												</tr>";
       											}
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [Robinhol](https://wordpress.org/support/users/robinhol/)
 * (@robinhol)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/plugin-woocommerce-booking-plugin/#post-5227413)
 * I have tried the
 * <?php $key_1_values = get_post_meta( 76, ‘key_1’ ); ?>
 * without any luck.
 * Does anyone have a tips?
 * Best regards

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Woocommerce booking plugin]’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [Robinhol](https://wordpress.org/support/users/robinhol/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/plugin-woocommerce-booking-plugin/#post-5227413)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
