2013-08-06 10:41:20 +00:00
< ? php
/**
2015-11-03 13:53:50 +00:00
* Order Data
2013-08-06 10:41:20 +00:00
*
* Functions for displaying the order data meta box .
*
2018-03-05 18:59:17 +00:00
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin / Meta Boxes
2014-06-11 19:50:15 +00:00
* @ version 2.2 . 0
2013-08-06 10:41:20 +00:00
*/
2014-06-11 19:50:15 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly
}
2013-08-06 10:41:20 +00:00
/**
2015-11-03 12:28:01 +00:00
* WC_Meta_Box_Order_Data Class .
2013-08-06 10:41:20 +00:00
*/
class WC_Meta_Box_Order_Data {
2014-06-11 19:50:15 +00:00
/**
2015-11-03 12:28:01 +00:00
* Billing fields .
2014-06-11 19:50:15 +00:00
*
* @ var array
*/
2014-11-26 21:53:06 +00:00
protected static $billing_fields = array ();
2014-06-11 19:50:15 +00:00
/**
2015-11-03 12:28:01 +00:00
* Shipping fields .
2014-06-11 19:50:15 +00:00
*
* @ var array
*/
2014-11-26 21:53:06 +00:00
protected static $shipping_fields = array ();
2013-08-06 10:41:20 +00:00
/**
2015-11-03 12:28:01 +00:00
* Init billing and shipping fields we display + save .
2013-08-06 10:41:20 +00:00
*/
public static function init_address_fields () {
2014-08-31 07:18:21 +00:00
2018-03-05 18:59:17 +00:00
self :: $billing_fields = apply_filters (
2019-12-20 18:25:23 +00:00
'woocommerce_admin_billing_fields' ,
array (
2018-03-05 18:59:17 +00:00
'first_name' => array (
'label' => __ ( 'First name' , 'woocommerce' ),
'show' => false ,
),
'last_name' => array (
'label' => __ ( 'Last name' , 'woocommerce' ),
'show' => false ,
),
'company' => array (
'label' => __ ( 'Company' , 'woocommerce' ),
'show' => false ,
),
'address_1' => array (
'label' => __ ( 'Address line 1' , 'woocommerce' ),
'show' => false ,
),
'address_2' => array (
'label' => __ ( 'Address line 2' , 'woocommerce' ),
'show' => false ,
),
'city' => array (
'label' => __ ( 'City' , 'woocommerce' ),
'show' => false ,
),
'postcode' => array (
'label' => __ ( 'Postcode / ZIP' , 'woocommerce' ),
'show' => false ,
),
'country' => array (
2020-01-30 11:42:41 +00:00
'label' => __ ( 'Country / Region' , 'woocommerce' ),
2018-03-05 18:59:17 +00:00
'show' => false ,
'class' => 'js_field-country select short' ,
'type' => 'select' ,
2020-01-30 11:42:41 +00:00
'options' => array ( '' => __ ( 'Select a country / region…' , 'woocommerce' ) ) + WC () -> countries -> get_allowed_countries (),
2018-03-05 18:59:17 +00:00
),
'state' => array (
'label' => __ ( 'State / County' , 'woocommerce' ),
'class' => 'js_field-state select short' ,
'show' => false ,
),
'email' => array (
'label' => __ ( 'Email address' , 'woocommerce' ),
),
'phone' => array (
'label' => __ ( 'Phone' , 'woocommerce' ),
),
)
);
self :: $shipping_fields = apply_filters (
2019-12-20 18:25:23 +00:00
'woocommerce_admin_shipping_fields' ,
array (
2018-03-05 18:59:17 +00:00
'first_name' => array (
'label' => __ ( 'First name' , 'woocommerce' ),
'show' => false ,
),
'last_name' => array (
'label' => __ ( 'Last name' , 'woocommerce' ),
'show' => false ,
),
'company' => array (
'label' => __ ( 'Company' , 'woocommerce' ),
'show' => false ,
),
'address_1' => array (
'label' => __ ( 'Address line 1' , 'woocommerce' ),
'show' => false ,
),
'address_2' => array (
'label' => __ ( 'Address line 2' , 'woocommerce' ),
'show' => false ,
),
'city' => array (
'label' => __ ( 'City' , 'woocommerce' ),
'show' => false ,
),
'postcode' => array (
'label' => __ ( 'Postcode / ZIP' , 'woocommerce' ),
'show' => false ,
),
'country' => array (
2020-01-30 11:42:41 +00:00
'label' => __ ( 'Country / Region' , 'woocommerce' ),
2018-03-05 18:59:17 +00:00
'show' => false ,
'type' => 'select' ,
'class' => 'js_field-country select short' ,
2020-01-30 11:42:41 +00:00
'options' => array ( '' => __ ( 'Select a country / region…' , 'woocommerce' ) ) + WC () -> countries -> get_shipping_countries (),
2018-03-05 18:59:17 +00:00
),
'state' => array (
'label' => __ ( 'State / County' , 'woocommerce' ),
'class' => 'js_field-state select short' ,
'show' => false ,
),
)
);
2013-08-06 10:41:20 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Output the metabox .
2016-01-04 21:31:36 +00:00
*
* @ param WP_Post $post
2013-08-06 10:41:20 +00:00
*/
public static function output ( $post ) {
global $theorder ;
2014-06-11 19:50:15 +00:00
if ( ! is_object ( $theorder ) ) {
2014-08-15 12:29:21 +00:00
$theorder = wc_get_order ( $post -> ID );
2014-06-11 19:50:15 +00:00
}
2013-08-06 10:41:20 +00:00
$order = $theorder ;
self :: init_address_fields ();
2014-06-27 12:12:10 +00:00
if ( WC () -> payment_gateways () ) {
$payment_gateways = WC () -> payment_gateways -> payment_gateways ();
2015-01-14 12:17:19 +00:00
} else {
$payment_gateways = array ();
2014-06-27 12:12:10 +00:00
}
2016-11-18 19:56:17 +00:00
$payment_method = $order -> get_payment_method ();
2014-06-27 12:12:10 +00:00
2015-04-29 20:01:34 +00:00
$order_type_object = get_post_type_object ( $post -> post_type );
2013-08-06 10:41:20 +00:00
wp_nonce_field ( 'woocommerce_save_data' , 'woocommerce_meta_nonce' );
?>
< style type = " text/css " >
2015-04-27 10:13:49 +00:00
#post-body-content, #titlediv { display:none }
2013-08-06 10:41:20 +00:00
</ style >
< div class = " panel-wrap woocommerce " >
2015-08-07 13:27:40 +00:00
< input name = " post_title " type = " hidden " value = " <?php echo empty( $post->post_title ) ? __( 'Order', 'woocommerce' ) : esc_attr( $post->post_title ); ?> " />
2015-04-27 10:13:49 +00:00
< input name = " post_status " type = " hidden " value = " <?php echo esc_attr( $post->post_status ); ?> " />
2017-11-01 12:32:35 +00:00
< div id = " order_data " class = " panel woocommerce-order-data " >
2018-03-05 18:59:17 +00:00
< h2 class = " woocommerce-order-data__heading " >
< ? php
/* translators: 1: order type 2: order number */
printf (
esc_html__ ( '%1$s #%2$s details' , 'woocommerce' ),
esc_html ( $order_type_object -> labels -> singular_name ),
esc_html ( $order -> get_order_number () )
2017-11-01 12:32:35 +00:00
);
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
?>
</ h2 >
< p class = " woocommerce-order-data__meta order_number " >
< ? php
$meta_list = array ();
2019-02-27 13:56:15 +00:00
if ( $payment_method && 'other' !== $payment_method ) {
2018-03-05 18:59:17 +00:00
/* translators: %s: payment method */
$payment_method_string = sprintf (
__ ( 'Payment via %s' , 'woocommerce' ),
esc_html ( isset ( $payment_gateways [ $payment_method ] ) ? $payment_gateways [ $payment_method ] -> get_title () : $payment_method )
);
if ( $transaction_id = $order -> get_transaction_id () ) {
if ( isset ( $payment_gateways [ $payment_method ] ) && ( $url = $payment_gateways [ $payment_method ] -> get_transaction_url ( $order ) ) ) {
$payment_method_string .= ' (<a href="' . esc_url ( $url ) . '" target="_blank">' . esc_html ( $transaction_id ) . '</a>)' ;
} else {
$payment_method_string .= ' (' . esc_html ( $transaction_id ) . ')' ;
}
2017-11-01 12:32:35 +00:00
}
2017-10-28 00:52:29 +00:00
2018-03-05 18:59:17 +00:00
$meta_list [] = $payment_method_string ;
}
2017-11-01 12:32:35 +00:00
2018-03-05 18:59:17 +00:00
if ( $order -> get_date_paid () ) {
/* translators: 1: date 2: time */
$meta_list [] = sprintf (
__ ( 'Paid on %1$s @ %2$s' , 'woocommerce' ),
wc_format_datetime ( $order -> get_date_paid () ),
wc_format_datetime ( $order -> get_date_paid (), get_option ( 'time_format' ) )
);
}
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
if ( $ip_address = $order -> get_customer_ip_address () ) {
/* translators: %s: IP address */
$meta_list [] = sprintf (
__ ( 'Customer IP: %s' , 'woocommerce' ),
'<span class="woocommerce-Order-customerIP">' . esc_html ( $ip_address ) . '</span>'
);
}
2017-11-01 12:32:35 +00:00
2018-03-05 18:59:17 +00:00
echo wp_kses_post ( implode ( '. ' , $meta_list ) );
2017-11-01 12:32:35 +00:00
2018-03-05 18:59:17 +00:00
?>
</ p >
2013-08-06 10:41:20 +00:00
< div class = " order_data_column_container " >
< div class = " order_data_column " >
2018-01-05 14:44:36 +00:00
< h3 >< ? php esc_html_e ( 'General' , 'woocommerce' ); ?> </h3>
2018-03-05 18:59:17 +00:00
< p class = " form-field form-field-wide " >
< label for = " order_date " >< ? php _e ( 'Date created:' , 'woocommerce' ); ?> </label>
2018-01-05 14:44:36 +00:00
< input type = " text " class = " date-picker " name = " order_date " maxlength = " 10 " value = " <?php echo esc_attr( date_i18n( 'Y-m-d', strtotime( $post->post_date ) ) ); ?> " pattern = " <?php echo esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9] { 4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ); ?> " />@
& lrm ;
2018-03-05 18:59:17 +00:00
< input type = " number " class = " hour " placeholder = " <?php esc_attr_e( 'h', 'woocommerce' ); ?> " name = " order_date_hour " min = " 0 " max = " 23 " step = " 1 " value = " <?php echo esc_attr( date_i18n( 'H', strtotime( $post->post_date ) ) ); ?> " pattern = " ([01]?[0-9] { 1}|2[0-3] { 1}) " />:
< input type = " number " class = " minute " placeholder = " <?php esc_attr_e( 'm', 'woocommerce' ); ?> " name = " order_date_minute " min = " 0 " max = " 59 " step = " 1 " value = " <?php echo esc_attr( date_i18n( 'i', strtotime( $post->post_date ) ) ); ?> " pattern = " [0-5] { 1}[0-9] { 1} " />
2018-01-05 14:44:36 +00:00
< input type = " hidden " name = " order_date_second " value = " <?php echo esc_attr( date_i18n( 's', strtotime( $post->post_date ) ) ); ?> " />
2013-08-16 15:43:26 +00:00
</ p >
2018-03-05 18:59:17 +00:00
< p class = " form-field form-field-wide wc-order-status " >
< label for = " order_status " >
< ? php
_e ( 'Status:' , 'woocommerce' );
if ( $order -> needs_payment () ) {
printf (
'<a href="%s">%s</a>' ,
esc_url ( $order -> get_checkout_payment_url () ),
__ ( 'Customer payment page →' , 'woocommerce' )
);
}
?>
</ label >
< select id = " order_status " name = " order_status " class = " wc-enhanced-select " >
< ? php
2014-05-30 16:47:00 +00:00
$statuses = wc_get_order_statuses ();
foreach ( $statuses as $status => $status_name ) {
2016-11-18 19:56:17 +00:00
echo '<option value="' . esc_attr ( $status ) . '" ' . selected ( $status , 'wc-' . $order -> get_status ( 'edit' ), false ) . '>' . esc_html ( $status_name ) . '</option>' ;
2013-08-06 10:41:20 +00:00
}
2018-03-05 18:59:17 +00:00
?>
</ select >
</ p >
2013-08-06 10:41:20 +00:00
2015-01-13 12:27:07 +00:00
< p class = " form-field form-field-wide wc-customer-user " >
2017-07-07 21:26:53 +00:00
<!-- email_off --> <!-- Disable CloudFlare email obfuscation -->
2018-03-05 18:59:17 +00:00
< label for = " customer_user " >
< ? php
_e ( 'Customer:' , 'woocommerce' );
2016-11-18 19:56:17 +00:00
if ( $order -> get_user_id ( 'edit' ) ) {
2016-08-27 03:56:09 +00:00
$args = array (
'post_status' => 'all' ,
2015-01-13 12:27:07 +00:00
'post_type' => 'shop_order' ,
2016-11-18 19:56:17 +00:00
'_customer_user' => $order -> get_user_id ( 'edit' ),
2015-01-13 12:27:07 +00:00
);
2018-03-05 18:59:17 +00:00
printf (
'<a href="%s">%s</a>' ,
2015-01-13 12:27:07 +00:00
esc_url ( add_query_arg ( $args , admin_url ( 'edit.php' ) ) ),
2018-02-26 18:19:03 +00:00
' ' . __ ( 'View other orders →' , 'woocommerce' )
);
2018-03-05 18:59:17 +00:00
printf (
'<a href="%s">%s</a>' ,
2018-02-26 18:19:03 +00:00
esc_url ( add_query_arg ( 'user_id' , $order -> get_user_id ( 'edit' ), admin_url ( 'user-edit.php' ) ) ),
' ' . __ ( 'Profile →' , 'woocommerce' )
2015-01-13 12:27:07 +00:00
);
}
2018-03-05 18:59:17 +00:00
?>
</ label >
2015-01-12 13:04:19 +00:00
< ? php
$user_string = '' ;
$user_id = '' ;
2016-08-15 16:50:02 +00:00
if ( $order -> get_user_id () ) {
2018-03-05 18:59:17 +00:00
$user_id = absint ( $order -> get_user_id () );
$user = get_user_by ( 'id' , $user_id );
2016-10-29 10:16:03 +00:00
/* translators: 1: user display name 2: user ID 3: user email */
2016-10-13 16:34:48 +00:00
$user_string = sprintf (
esc_html__ ( '%1$s (#%2$s – %3$s)' , 'woocommerce' ),
$user -> display_name ,
absint ( $user -> ID ),
$user -> user_email
);
2015-01-12 13:04:19 +00:00
}
?>
2016-12-21 14:18:33 +00:00
< select class = " wc-customer-search " id = " customer_user " name = " customer_user " data - placeholder = " <?php esc_attr_e( 'Guest', 'woocommerce' ); ?> " data - allow_clear = " true " >
2019-04-17 11:02:20 +00:00
< option value = " <?php echo esc_attr( $user_id ); ?> " selected = " selected " >< ? php echo htmlspecialchars ( wp_kses_post ( $user_string ) ); // htmlspecialchars to prevent XSS when rendered by selectWoo. ?></option>
2016-12-21 14:18:33 +00:00
</ select >
2017-07-07 18:45:05 +00:00
<!--/ email_off -->
2013-08-06 10:41:20 +00:00
</ p >
2015-01-13 12:27:07 +00:00
< ? php do_action ( 'woocommerce_admin_order_data_after_order_details' , $order ); ?>
2013-08-06 10:41:20 +00:00
</ div >
< div class = " order_data_column " >
2016-02-17 17:02:27 +00:00
< h3 >
2018-01-05 14:44:36 +00:00
< ? php esc_html_e ( 'Billing' , 'woocommerce' ); ?>
< a href = " # " class = " edit_address " >< ? php esc_html_e ( 'Edit' , 'woocommerce' ); ?> </a>
2016-11-17 12:38:15 +00:00
< span >
2018-01-05 14:44:36 +00:00
< a href = " # " class = " load_customer_billing " style = " display:none; " >< ? php esc_html_e ( 'Load billing address' , 'woocommerce' ); ?> </a>
2016-11-17 12:38:15 +00:00
</ span >
2016-02-17 17:02:27 +00:00
</ h3 >
2018-03-05 18:59:17 +00:00
< div class = " address " >
< ? php
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
// Display values.
if ( $order -> get_formatted_billing_address () ) {
echo '<p>' . wp_kses ( $order -> get_formatted_billing_address (), array ( 'br' => array () ) ) . '</p>' ;
} else {
echo '<p class="none_set"><strong>' . __ ( 'Address:' , 'woocommerce' ) . '</strong> ' . __ ( 'No billing address set.' , 'woocommerce' ) . '</p>' ;
}
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
foreach ( self :: $billing_fields as $key => $field ) {
if ( isset ( $field [ 'show' ] ) && false === $field [ 'show' ] ) {
continue ;
}
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
$field_name = 'billing_' . $key ;
2016-11-18 19:40:32 +00:00
2018-06-07 06:58:04 +00:00
if ( isset ( $field [ 'value' ] ) ) {
$field_value = $field [ 'value' ];
} elseif ( is_callable ( array ( $order , 'get_' . $field_name ) ) ) {
2018-03-05 18:59:17 +00:00
$field_value = $order -> { " get_ $field_name " }( 'edit' );
} else {
$field_value = $order -> get_meta ( '_' . $field_name );
}
2017-06-05 19:15:04 +00:00
2018-03-05 18:59:17 +00:00
if ( 'billing_phone' === $field_name ) {
$field_value = wc_make_phone_clickable ( $field_value );
} else {
$field_value = make_clickable ( esc_html ( $field_value ) );
2013-08-06 10:41:20 +00:00
}
2018-03-16 13:53:18 +00:00
if ( $field_value ) {
echo '<p><strong>' . esc_html ( $field [ 'label' ] ) . ':</strong> ' . wp_kses_post ( $field_value ) . '</p>' ;
}
2018-03-05 18:59:17 +00:00
}
?>
</ div >
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
< div class = " edit_address " >
< ? php
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
// Display form.
2013-08-06 10:41:20 +00:00
foreach ( self :: $billing_fields as $key => $field ) {
2014-06-11 19:50:15 +00:00
if ( ! isset ( $field [ 'type' ] ) ) {
2013-08-06 10:41:20 +00:00
$field [ 'type' ] = 'text' ;
2014-06-11 19:50:15 +00:00
}
2016-08-27 04:47:24 +00:00
if ( ! isset ( $field [ 'id' ] ) ) {
2014-08-01 04:26:45 +00:00
$field [ 'id' ] = '_billing_' . $key ;
}
2018-03-09 16:25:42 +00:00
$field_name = 'billing_' . $key ;
2018-06-07 06:58:04 +00:00
if ( ! isset ( $field [ 'value' ] ) ) {
if ( is_callable ( array ( $order , 'get_' . $field_name ) ) ) {
$field [ 'value' ] = $order -> { " get_ $field_name " }( 'edit' );
} else {
$field [ 'value' ] = $order -> get_meta ( '_' . $field_name );
}
2018-03-09 16:25:42 +00:00
}
2013-08-06 10:41:20 +00:00
switch ( $field [ 'type' ] ) {
2018-03-05 18:59:17 +00:00
case 'select' :
2014-08-01 04:26:45 +00:00
woocommerce_wp_select ( $field );
2018-03-05 18:59:17 +00:00
break ;
default :
2014-08-01 04:26:45 +00:00
woocommerce_wp_text_input ( $field );
2018-03-05 18:59:17 +00:00
break ;
2013-08-06 10:41:20 +00:00
}
}
2013-08-16 15:43:26 +00:00
?>
< p class = " form-field form-field-wide " >
2018-01-05 14:44:36 +00:00
< label >< ? php esc_html_e ( 'Payment method:' , 'woocommerce' ); ?> </label>
2013-08-16 15:43:26 +00:00
< select name = " _payment_method " id = " _payment_method " class = " first " >
2018-01-05 14:44:36 +00:00
< option value = " " >< ? php esc_html_e ( 'N/A' , 'woocommerce' ); ?> </option>
2013-08-16 15:43:26 +00:00
< ? php
2018-03-05 18:59:17 +00:00
$found_method = false ;
foreach ( $payment_gateways as $gateway ) {
if ( 'yes' === $gateway -> enabled ) {
echo '<option value="' . esc_attr ( $gateway -> id ) . '" ' . selected ( $payment_method , $gateway -> id , false ) . '>' . esc_html ( $gateway -> get_title () ) . '</option>' ;
if ( $payment_method == $gateway -> id ) {
$found_method = true ;
2013-08-16 15:43:26 +00:00
}
}
2018-03-05 18:59:17 +00:00
}
2013-08-16 15:43:26 +00:00
2018-03-05 18:59:17 +00:00
if ( ! $found_method && ! empty ( $payment_method ) ) {
2020-06-16 15:15:12 +00:00
echo '<option value="' . esc_attr ( $payment_method ) . '" selected="selected">' . esc_html__ ( 'Other' , 'woocommerce' ) . '</option>' ;
2018-03-05 18:59:17 +00:00
} else {
2020-06-16 15:15:12 +00:00
echo '<option value="other">' . esc_html__ ( 'Other' , 'woocommerce' ) . '</option>' ;
2018-03-05 18:59:17 +00:00
}
2013-08-16 15:43:26 +00:00
?>
</ select >
</ p >
< ? php
2018-03-05 18:59:17 +00:00
woocommerce_wp_text_input (
array (
'id' => '_transaction_id' ,
'label' => __ ( 'Transaction ID' , 'woocommerce' ),
2018-04-10 12:01:52 +00:00
'value' => $order -> get_transaction_id ( 'edit' ),
2018-03-05 18:59:17 +00:00
)
);
?>
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
</ div >
< ? php do_action ( 'woocommerce_admin_order_data_after_billing_address' , $order ); ?>
2013-08-06 10:41:20 +00:00
</ div >
< div class = " order_data_column " >
2016-02-17 17:02:27 +00:00
< h3 >
2018-01-05 14:44:36 +00:00
< ? php esc_html_e ( 'Shipping' , 'woocommerce' ); ?>
< a href = " # " class = " edit_address " >< ? php esc_html_e ( 'Edit' , 'woocommerce' ); ?> </a>
2016-11-17 12:38:15 +00:00
< span >
2018-01-05 14:44:36 +00:00
< a href = " # " class = " load_customer_shipping " style = " display:none; " >< ? php esc_html_e ( 'Load shipping address' , 'woocommerce' ); ?> </a>
< a href = " # " class = " billing-same-as-shipping " style = " display:none; " >< ? php esc_html_e ( 'Copy billing address' , 'woocommerce' ); ?> </a>
2016-11-17 12:38:15 +00:00
</ span >
2016-02-17 17:02:27 +00:00
</ h3 >
2018-03-05 18:59:17 +00:00
< div class = " address " >
< ? php
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
// Display values.
if ( $order -> get_formatted_shipping_address () ) {
echo '<p>' . wp_kses ( $order -> get_formatted_shipping_address (), array ( 'br' => array () ) ) . '</p>' ;
} else {
echo '<p class="none_set"><strong>' . __ ( 'Address:' , 'woocommerce' ) . '</strong> ' . __ ( 'No shipping address set.' , 'woocommerce' ) . '</p>' ;
}
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
if ( ! empty ( self :: $shipping_fields ) ) {
foreach ( self :: $shipping_fields as $key => $field ) {
if ( isset ( $field [ 'show' ] ) && false === $field [ 'show' ] ) {
continue ;
}
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
$field_name = 'shipping_' . $key ;
2016-11-18 19:40:32 +00:00
2018-03-05 18:59:17 +00:00
if ( is_callable ( array ( $order , 'get_' . $field_name ) ) ) {
$field_value = $order -> { " get_ $field_name " }( 'edit' );
} else {
$field_value = $order -> get_meta ( '_' . $field_name );
2014-06-11 19:50:15 +00:00
}
2013-08-06 10:41:20 +00:00
2018-03-16 13:53:18 +00:00
if ( $field_value ) {
echo '<p><strong>' . esc_html ( $field [ 'label' ] ) . ':</strong> ' . wp_kses_post ( $field_value ) . '</p>' ;
}
2014-06-11 19:50:15 +00:00
}
2018-03-05 18:59:17 +00:00
}
2013-08-16 15:43:26 +00:00
2018-03-05 18:59:17 +00:00
if ( apply_filters ( 'woocommerce_enable_order_notes_field' , 'yes' == get_option ( 'woocommerce_enable_order_comments' , 'yes' ) ) && $post -> post_excerpt ) {
2018-05-02 14:14:24 +00:00
echo '<p class="order_note"><strong>' . __ ( 'Customer provided note:' , 'woocommerce' ) . '</strong> ' . nl2br ( esc_html ( $post -> post_excerpt ) ) . '</p>' ;
2018-03-05 18:59:17 +00:00
}
?>
</ div >
< div class = " edit_address " >
< ? php
2013-08-06 10:41:20 +00:00
2018-03-05 18:59:17 +00:00
// Display form.
2015-04-01 13:33:56 +00:00
if ( ! empty ( self :: $shipping_fields ) ) {
2014-06-11 19:50:15 +00:00
foreach ( self :: $shipping_fields as $key => $field ) {
if ( ! isset ( $field [ 'type' ] ) ) {
$field [ 'type' ] = 'text' ;
}
2016-08-27 04:47:24 +00:00
if ( ! isset ( $field [ 'id' ] ) ) {
2014-08-01 04:26:45 +00:00
$field [ 'id' ] = '_shipping_' . $key ;
}
2014-06-11 19:50:15 +00:00
2018-03-09 16:25:42 +00:00
$field_name = 'shipping_' . $key ;
if ( is_callable ( array ( $order , 'get_' . $field_name ) ) ) {
$field [ 'value' ] = $order -> { " get_ $field_name " }( 'edit' );
} else {
$field [ 'value' ] = $order -> get_meta ( '_' . $field_name );
}
2014-06-11 19:50:15 +00:00
switch ( $field [ 'type' ] ) {
2018-03-05 18:59:17 +00:00
case 'select' :
2014-08-01 04:26:45 +00:00
woocommerce_wp_select ( $field );
2018-03-05 18:59:17 +00:00
break ;
default :
2014-08-01 04:26:45 +00:00
woocommerce_wp_text_input ( $field );
2018-03-05 18:59:17 +00:00
break ;
2014-06-11 19:50:15 +00:00
}
2013-08-06 10:41:20 +00:00
}
}
2018-03-05 18:59:17 +00:00
if ( apply_filters ( 'woocommerce_enable_order_notes_field' , 'yes' == get_option ( 'woocommerce_enable_order_comments' , 'yes' ) ) ) :
2013-08-16 15:43:26 +00:00
?>
2018-03-05 18:59:17 +00:00
< p class = " form-field form-field-wide " >
< label for = " excerpt " >< ? php _e ( 'Customer provided note' , 'woocommerce' ); ?> :</label>
< textarea rows = " 1 " cols = " 40 " name = " excerpt " tabindex = " 6 " id = " excerpt " placeholder = " <?php esc_attr_e( 'Customer notes about the order', 'woocommerce' ); ?> " >< ? php echo wp_kses_post ( $post -> post_excerpt ); ?> </textarea>
</ p >
< ? php endif ; ?>
</ div >
< ? php do_action ( 'woocommerce_admin_order_data_after_shipping_address' , $order ); ?>
2013-08-06 10:41:20 +00:00
</ div >
</ div >
< div class = " clear " ></ div >
</ div >
</ div >
< ? php
}
/**
2015-11-03 12:28:01 +00:00
* Save meta box data .
2016-01-04 21:31:36 +00:00
*
2016-10-28 09:52:01 +00:00
* @ param int $order_id Order ID .
2013-08-06 10:41:20 +00:00
*/
2016-10-28 09:52:01 +00:00
public static function save ( $order_id ) {
2013-08-06 10:41:20 +00:00
self :: init_address_fields ();
2016-10-28 09:52:01 +00:00
// Ensure gateways are loaded in case they need to insert data into the emails.
2016-03-03 17:05:40 +00:00
WC () -> payment_gateways ();
WC () -> shipping ();
2016-10-28 09:52:01 +00:00
// Get order object.
$order = wc_get_order ( $order_id );
2017-06-30 10:40:52 +00:00
$props = array ();
2016-03-14 14:36:28 +00:00
2016-10-28 09:52:01 +00:00
// Create order key.
if ( ! $order -> get_order_key () ) {
2019-01-21 16:02:28 +00:00
$props [ 'order_key' ] = wc_generate_order_key ();
2016-10-28 09:52:01 +00:00
}
2013-08-06 10:41:20 +00:00
2016-10-28 09:52:01 +00:00
// Update customer.
2017-04-28 16:13:18 +00:00
$customer_id = isset ( $_POST [ 'customer_user' ] ) ? absint ( $_POST [ 'customer_user' ] ) : 0 ;
2016-10-28 09:52:01 +00:00
if ( $customer_id !== $order -> get_customer_id () ) {
$props [ 'customer_id' ] = $customer_id ;
2016-03-14 14:36:28 +00:00
}
2013-08-06 10:41:20 +00:00
2016-10-28 09:52:01 +00:00
// Update billing fields.
2015-04-01 13:33:56 +00:00
if ( ! empty ( self :: $billing_fields ) ) {
2014-06-11 19:50:15 +00:00
foreach ( self :: $billing_fields as $key => $field ) {
2016-08-27 04:47:24 +00:00
if ( ! isset ( $field [ 'id' ] ) ) {
2014-12-08 12:30:06 +00:00
$field [ 'id' ] = '_billing_' . $key ;
}
2016-10-28 09:52:01 +00:00
2017-03-13 16:55:18 +00:00
if ( ! isset ( $_POST [ $field [ 'id' ] ] ) ) {
continue ;
}
2016-11-18 19:40:32 +00:00
if ( is_callable ( array ( $order , 'set_billing_' . $key ) ) ) {
2019-04-18 17:52:51 +00:00
$props [ 'billing_' . $key ] = wc_clean ( wp_unslash ( $_POST [ $field [ 'id' ] ] ) );
2016-11-18 19:40:32 +00:00
} else {
2019-04-18 17:52:51 +00:00
$order -> update_meta_data ( $field [ 'id' ], wc_clean ( wp_unslash ( $_POST [ $field [ 'id' ] ] ) ) );
2016-11-18 19:40:32 +00:00
}
2014-06-11 19:50:15 +00:00
}
}
2013-08-06 10:41:20 +00:00
2016-10-28 09:52:01 +00:00
// Update shipping fields.
2015-04-01 13:35:53 +00:00
if ( ! empty ( self :: $shipping_fields ) ) {
2014-06-11 19:50:15 +00:00
foreach ( self :: $shipping_fields as $key => $field ) {
2016-08-27 04:47:24 +00:00
if ( ! isset ( $field [ 'id' ] ) ) {
2014-12-08 12:30:06 +00:00
$field [ 'id' ] = '_shipping_' . $key ;
}
2016-10-28 09:52:01 +00:00
2017-03-13 16:55:18 +00:00
if ( ! isset ( $_POST [ $field [ 'id' ] ] ) ) {
continue ;
}
2016-11-18 19:40:32 +00:00
if ( is_callable ( array ( $order , 'set_shipping_' . $key ) ) ) {
2019-04-18 17:52:51 +00:00
$props [ 'shipping_' . $key ] = wc_clean ( wp_unslash ( $_POST [ $field [ 'id' ] ] ) );
2016-11-18 19:40:32 +00:00
} else {
2019-04-18 17:52:51 +00:00
$order -> update_meta_data ( $field [ 'id' ], wc_clean ( wp_unslash ( $_POST [ $field [ 'id' ] ] ) ) );
2016-11-18 19:40:32 +00:00
}
2014-06-11 19:50:15 +00:00
}
}
2013-08-06 10:41:20 +00:00
2014-06-27 12:12:10 +00:00
if ( isset ( $_POST [ '_transaction_id' ] ) ) {
2019-04-18 17:52:51 +00:00
$props [ 'transaction_id' ] = wc_clean ( wp_unslash ( $_POST [ '_transaction_id' ] ) );
2014-06-27 12:12:10 +00:00
}
2016-10-28 09:52:01 +00:00
// Payment method handling.
if ( $order -> get_payment_method () !== wp_unslash ( $_POST [ '_payment_method' ] ) ) {
2014-06-11 19:50:15 +00:00
$methods = WC () -> payment_gateways -> payment_gateways ();
2019-04-18 17:52:51 +00:00
$payment_method = wc_clean ( wp_unslash ( $_POST [ '_payment_method' ] ) );
2014-06-11 19:50:15 +00:00
$payment_method_title = $payment_method ;
2013-08-16 15:43:26 +00:00
2016-09-02 01:33:57 +00:00
if ( isset ( $methods ) && isset ( $methods [ $payment_method ] ) ) {
2013-08-16 15:43:26 +00:00
$payment_method_title = $methods [ $payment_method ] -> get_title ();
2014-06-11 19:50:15 +00:00
}
2013-08-16 15:43:26 +00:00
2018-03-05 18:59:17 +00:00
$props [ 'payment_method' ] = $payment_method ;
2016-10-28 09:52:01 +00:00
$props [ 'payment_method_title' ] = $payment_method_title ;
2013-08-16 15:43:26 +00:00
}
2016-10-28 09:52:01 +00:00
// Update date.
2013-08-06 10:41:20 +00:00
if ( empty ( $_POST [ 'order_date' ] ) ) {
2019-12-20 17:23:05 +00:00
$date = time ();
2013-08-06 10:41:20 +00:00
} else {
2018-01-05 14:44:36 +00:00
$date = gmdate ( 'Y-m-d H:i:s' , strtotime ( $_POST [ 'order_date' ] . ' ' . ( int ) $_POST [ 'order_date_hour' ] . ':' . ( int ) $_POST [ 'order_date_minute' ] . ':' . ( int ) $_POST [ 'order_date_second' ] ) );
2013-08-06 10:41:20 +00:00
}
2016-10-28 09:52:01 +00:00
$props [ 'date_created' ] = $date ;
2013-08-06 10:41:20 +00:00
2018-04-05 11:58:51 +00:00
// Set created via prop if new post.
if ( isset ( $_POST [ 'original_post_status' ] ) && $_POST [ 'original_post_status' ] === 'auto-draft' ) {
$props [ 'created_via' ] = 'admin' ;
}
2016-10-28 09:52:01 +00:00
// Save order data.
$order -> set_props ( $props );
2019-04-18 17:52:51 +00:00
$order -> set_status ( wc_clean ( wp_unslash ( $_POST [ 'order_status' ] ) ), '' , true );
2016-10-28 09:52:01 +00:00
$order -> save ();
2013-08-06 10:41:20 +00:00
}
2014-06-11 20:12:23 +00:00
}