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
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class BKAP_Customer_Meta_Box {
public $id;
public $title;
public $context;
public $priority;
public $post_types;
public function __construct() {
$this->id = 'bkap-customer-data';
$this->title = __( 'Customer details', 'woocommerce-booking' );
$this->context = 'side';
$this->priority = 'default';
$this->post_types = array( 'bkap_booking' );
}
public function meta_box_inner( $post ) {
global $booking;
if ( get_post_type( $post->ID ) === 'bkap_booking' ) {
$booking = new BKAP_Booking( $post->ID );
}
$has_data = false;
?>
<table class="booking-customer-details">
<?php
if ( $booking->get_customer_id() && ( $user = get_user_by( 'id', $booking->get_customer_id() ) ) ) {
?>
<tr>
<th><?php esc_html_e( 'Name:', 'woocommerce-booking' ); ?></th>
<td><?php echo esc_html( $user->last_name && $user->first_name ? $user->first_name . ' ' . $user->last_name : '—' ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Email:', 'woocommerce-booking' ); ?></th>
<td><?php echo make_clickable( sanitize_email( $user->user_email ) ); ?></td>
</tr>
<tr class="view">
<th> </th>
<td><a class="button button-small" target="_blank" href="<?php echo esc_url( admin_url( 'user-edit.php?user_id=' . absint( $user->ID ) ) ); ?>"><?php echo esc_html( 'View User', 'woocommerce-booking' ); ?></a></td>
</tr>
<?php
$has_data = true;
}
if ( $booking->get_order_id() && ( $order = wc_get_order( $booking->get_order_id() ) ) ) {
?>
<tr>
<th valign='top'><?php esc_html_e( 'Address:', 'woocommerce-booking' ); ?></th>
<td><?php echo wp_kses( $order->get_formatted_billing_address() ? $order->get_formatted_billing_address() : __( 'No billing address set.', 'woocommerce-booking' ), array( 'br' => array() ) ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Email:', 'woocommerce-booking' ); ?></th>
<td><?php echo make_clickable( sanitize_email( is_callable( array( $order, 'get_billing_email' ) ) ? $order->get_billing_email() : $order->billing_email ) ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Phone:', 'woocommerce-booking' ); ?></th>
<td><?php echo esc_html( is_callable( array( $order, 'get_billing_phone' ) ) ? $order->get_billing_phone() : $order->billing_phone ); ?></td>
</tr>
<tr class="view">
<th> </th>
<td><a class="button button-small" target="_blank" href="<?php echo esc_url( admin_url( 'post.php?post=' . absint( $booking->get_order_id() ) . '&action=edit' ) ); ?>"><?php echo esc_html( 'View Order', 'woocommerce-booking' ); ?></a></td>
</tr>
<?php
$has_data = true;
}
if ( ! $has_data ) {
?>
<tr>
<td colspan="2"><?php esc_html_e( 'N/A', 'woocommerce-booking' ); ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
}
return new BKAP_Customer_Meta_Box();
?>