Completed
Push — master ( 4e1a3d...0516d6 )
by Mike
07:57
created

WC_Meta_Box_Order_Data::output()   F

Complexity

Conditions 43
Paths > 20000

Size

Total Lines 264
Code Lines 161

Duplication

Lines 73
Ratio 27.65 %
Metric Value
dl 73
loc 264
rs 2
cc 43
eloc 161
nc 18874368
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 20 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Order Data
4
 *
5
 * Functions for displaying the order data meta box.
6
 *
7
 * @author 		WooThemes
8
 * @category 	Admin
9
 * @package 	WooCommerce/Admin/Meta Boxes
10
 * @version     2.2.0
11
 */
12
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit; // Exit if accessed directly
15
}
16
17
/**
18
 * WC_Meta_Box_Order_Data Class.
19
 */
20
class WC_Meta_Box_Order_Data {
21
22
	/**
23
	 * Billing fields.
24
	 *
25
	 * @var array
26
	 */
27
	protected static $billing_fields = array();
28
29
	/**
30
	 * Shipping fields.
31
	 *
32
	 * @var array
33
	 */
34
	protected static $shipping_fields = array();
35
36
	/**
37
	 * Init billing and shipping fields we display + save.
38
	 */
39
	public static function init_address_fields() {
40
41
		self::$billing_fields = apply_filters( 'woocommerce_admin_billing_fields', array(
42
			'first_name' => array(
43
				'label' => __( 'First Name', 'woocommerce' ),
44
				'show'  => false
45
			),
46
			'last_name' => array(
47
				'label' => __( 'Last Name', 'woocommerce' ),
48
				'show'  => false
49
			),
50
			'company' => array(
51
				'label' => __( 'Company', 'woocommerce' ),
52
				'show'  => false
53
			),
54
			'address_1' => array(
55
				'label' => __( 'Address 1', 'woocommerce' ),
56
				'show'  => false
57
			),
58
			'address_2' => array(
59
				'label' => __( 'Address 2', 'woocommerce' ),
60
				'show'  => false
61
			),
62
			'city' => array(
63
				'label' => __( 'City', 'woocommerce' ),
64
				'show'  => false
65
			),
66
			'postcode' => array(
67
				'label' => __( 'Postcode', 'woocommerce' ),
68
				'show'  => false
69
			),
70
			'country' => array(
71
				'label'   => __( 'Country', 'woocommerce' ),
72
				'show'    => false,
73
				'class'   => 'js_field-country select short',
74
				'type'    => 'select',
75
				'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_allowed_countries()
76
			),
77
			'state' => array(
78
				'label' => __( 'State/County', 'woocommerce' ),
79
				'class'   => 'js_field-state select short',
80
				'show'  => false
81
			),
82
			'email' => array(
83
				'label' => __( 'Email', 'woocommerce' ),
84
			),
85
			'phone' => array(
86
				'label' => __( 'Phone', 'woocommerce' ),
87
			),
88
		) );
89
90
		self::$shipping_fields = apply_filters( 'woocommerce_admin_shipping_fields', array(
91
			'first_name' => array(
92
				'label' => __( 'First Name', 'woocommerce' ),
93
				'show'  => false
94
			),
95
			'last_name' => array(
96
				'label' => __( 'Last Name', 'woocommerce' ),
97
				'show'  => false
98
			),
99
			'company' => array(
100
				'label' => __( 'Company', 'woocommerce' ),
101
				'show'  => false
102
			),
103
			'address_1' => array(
104
				'label' => __( 'Address 1', 'woocommerce' ),
105
				'show'  => false
106
			),
107
			'address_2' => array(
108
				'label' => __( 'Address 2', 'woocommerce' ),
109
				'show'  => false
110
			),
111
			'city' => array(
112
				'label' => __( 'City', 'woocommerce' ),
113
				'show'  => false
114
			),
115
			'postcode' => array(
116
				'label' => __( 'Postcode', 'woocommerce' ),
117
				'show'  => false
118
			),
119
			'country' => array(
120
				'label'   => __( 'Country', 'woocommerce' ),
121
				'show'    => false,
122
				'type'    => 'select',
123
				'class'   => 'js_field-country select short',
124
				'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_shipping_countries()
125
			),
126
			'state' => array(
127
				'label' => __( 'State/County', 'woocommerce' ),
128
				'class'   => 'js_field-state select short',
129
				'show'  => false
130
			),
131
		) );
132
	}
133
134
	/**
135
	 * Output the metabox.
136
	 *
137
	 * @param WP_Post $post
138
	 */
139
	public static function output( $post ) {
140
		global $theorder;
141
142
		if ( ! is_object( $theorder ) ) {
143
			$theorder = wc_get_order( $post->ID );
144
		}
145
146
		$order = $theorder;
147
148
		self::init_address_fields();
149
150
		if ( WC()->payment_gateways() ) {
151
			$payment_gateways = WC()->payment_gateways->payment_gateways();
152
		} else {
153
			$payment_gateways = array();
154
		}
155
156
		$payment_method = ! empty( $order->payment_method ) ? $order->payment_method : '';
157
158
		$order_type_object = get_post_type_object( $post->post_type );
159
		wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
160
		?>
161
		<style type="text/css">
162
			#post-body-content, #titlediv { display:none }
163
		</style>
164
		<div class="panel-wrap woocommerce">
165
			<input name="post_title" type="hidden" value="<?php echo empty( $post->post_title ) ? __( 'Order', 'woocommerce' ) : esc_attr( $post->post_title ); ?>" />
166
			<input name="post_status" type="hidden" value="<?php echo esc_attr( $post->post_status ); ?>" />
167
			<div id="order_data" class="panel">
168
169
				<h2><?php echo esc_html( sprintf( _x( '%s #%s details', 'Order #123 details', 'woocommerce' ), $order_type_object->labels->singular_name, $order->get_order_number() ) ); ?></h2>
170
				<p class="order_number"><?php
171
172
					if ( $payment_method ) {
173
						printf( __( 'Payment via %s', 'woocommerce' ), ( isset( $payment_gateways[ $payment_method ] ) ? esc_html( $payment_gateways[ $payment_method ]->get_title() ) : esc_html( $payment_method ) ) );
174
175
						if ( $transaction_id = $order->get_transaction_id() ) {
176
								if ( isset( $payment_gateways[ $payment_method ] ) && ( $url = $payment_gateways[ $payment_method ]->get_transaction_url( $order ) ) ) {
177
								echo ' (<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $transaction_id ) . '</a>)';
178
							} else {
179
								echo ' (' . esc_html( $transaction_id ) . ')';
180
							}
181
						}
182
						echo '. ';
183
					}
184
185 View Code Duplication
					if ( $ip_address = get_post_meta( $post->ID, '_customer_ip_address', true ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
186
						echo __( 'Customer IP', 'woocommerce' ) . ': ' . esc_html( $ip_address );
187
					}
188
				?></p>
189
190
				<div class="order_data_column_container">
191
					<div class="order_data_column">
192
						<h3><?php _e( 'General Details', 'woocommerce' ); ?></h3>
193
194
						<p class="form-field form-field-wide"><label for="order_date"><?php _e( 'Order date:', 'woocommerce' ) ?></label>
195
							<input type="text" class="date-picker" name="order_date" id="order_date" maxlength="10" value="<?php echo date_i18n( 'Y-m-d', strtotime( $post->post_date ) ); ?>" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />@<input type="text" class="hour" placeholder="<?php esc_attr_e( 'h', 'woocommerce' ) ?>" name="order_date_hour" id="order_date_hour" maxlength="2" size="2" value="<?php echo date_i18n( 'H', strtotime( $post->post_date ) ); ?>" pattern="\-?\d+(\.\d{0,})?" />:<input type="text" class="minute" placeholder="<?php esc_attr_e( 'm', 'woocommerce' ) ?>" name="order_date_minute" id="order_date_minute" maxlength="2" size="2" value="<?php echo date_i18n( 'i', strtotime( $post->post_date ) ); ?>" pattern="\-?\d+(\.\d{0,})?" />
196
						</p>
197
198
						<p class="form-field form-field-wide wc-order-status"><label for="order_status"><?php _e( 'Order status:', 'woocommerce' ) ?> <?php
199
							if ( $order->has_status( 'pending' ) ) {
200
								printf( '<a href="%s">%s &rarr;</a>',
201
									esc_url( $order->get_checkout_payment_url() ),
202
									__( 'Customer payment page', 'woocommerce' )
203
								);
204
							}
205
						?></label>
206
						<select id="order_status" name="order_status" class="wc-enhanced-select">
207
							<?php
208
								$statuses = wc_get_order_statuses();
209
								foreach ( $statuses as $status => $status_name ) {
210
									echo '<option value="' . esc_attr( $status ) . '" ' . selected( $status, 'wc-' . $order->get_status(), false ) . '>' . esc_html( $status_name ) . '</option>';
211
								}
212
							?>
213
						</select></p>
214
215
						<p class="form-field form-field-wide wc-customer-user">
216
							<label for="customer_user"><?php _e( 'Customer:', 'woocommerce' ) ?> <?php
217
								if ( ! empty( $order->customer_user ) ) {
218
									$args = array( 'post_status' => 'all',
219
										'post_type'      => 'shop_order',
220
										'_customer_user' => absint( $order->customer_user )
221
									);
222
									printf( '<a href="%s">%s &rarr;</a>',
223
										esc_url( add_query_arg( $args, admin_url( 'edit.php' ) ) ),
224
										__( 'View other orders', 'woocommerce' )
225
									);
226
								}
227
							?></label>
228
							<?php
229
							$user_string = '';
230
							$user_id     = '';
231
							if ( ! empty( $order->customer_user ) ) {
232
								$user_id     = absint( $order->customer_user );
233
								$user        = get_user_by( 'id', $user_id );
234
								$user_string = esc_html( $user->display_name ) . ' (#' . absint( $user->ID ) . ' &ndash; ' . esc_html( $user->user_email ) . ')';
235
							}
236
							?>
237
							<input type="hidden" class="wc-customer-search" id="customer_user" name="customer_user" data-placeholder="<?php esc_attr_e( 'Guest', 'woocommerce' ); ?>" data-selected="<?php echo htmlspecialchars( $user_string ); ?>" value="<?php echo $user_id; ?>" data-allow_clear="true" />
238
						</p>
239
						<?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); ?>
240
					</div>
241
					<div class="order_data_column">
242
						<h3>
243
							<?php _e( 'Billing Details', 'woocommerce' ); ?>
244
							<a href="#" class="edit_address"><?php _e( 'Edit', 'woocommerce' ); ?></a>
245
							<a href="#" class="tips load_customer_billing" data-tip="<?php esc_attr_e( 'Load billing address', 'woocommerce' ); ?>" style="display:none;"><?php _e( 'Load billing address', 'woocommerce' ); ?></a>
246
						</h3>
247
						<?php
248
							// Display values
249
							echo '<div class="address">';
250
251 View Code Duplication
								if ( $order->get_formatted_billing_address() ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
252
									echo '<p><strong>' . __( 'Address', 'woocommerce' ) . ':</strong>' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '</p>';
253
								} else {
254
									echo '<p class="none_set"><strong>' . __( 'Address', 'woocommerce' ) . ':</strong> ' . __( 'No billing address set.', 'woocommerce' ) . '</p>';
255
								}
256
257 View Code Duplication
								foreach ( self::$billing_fields as $key => $field ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
258
									if ( isset( $field['show'] ) && false === $field['show'] ) {
259
										continue;
260
									}
261
262
									$field_name = 'billing_' . $key;
263
264
									if ( $order->$field_name ) {
265
										echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $order->$field_name ) ) . '</p>';
266
									}
267
								}
268
269
							echo '</div>';
270
271
							// Display form
272
							echo '<div class="edit_address">';
273
274 View Code Duplication
							foreach ( self::$billing_fields as $key => $field ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
275
								if ( ! isset( $field['type'] ) ) {
276
									$field['type'] = 'text';
277
								}
278
								if ( ! isset( $field['id'] ) ){
279
									$field['id'] = '_billing_' . $key;
280
								}
281
								switch ( $field['type'] ) {
282
									case 'select' :
283
										woocommerce_wp_select( $field );
284
									break;
285
									default :
286
										woocommerce_wp_text_input( $field );
287
									break;
288
								}
289
							}
290
							?>
291
							<p class="form-field form-field-wide">
292
								<label><?php _e( 'Payment Method:', 'woocommerce' ); ?></label>
293
								<select name="_payment_method" id="_payment_method" class="first">
294
									<option value=""><?php _e( 'N/A', 'woocommerce' ); ?></option>
295
									<?php
296
										$found_method 	= false;
297
298
										foreach ( $payment_gateways as $gateway ) {
299
											if ( $gateway->enabled == "yes" ) {
300
												echo '<option value="' . esc_attr( $gateway->id ) . '" ' . selected( $payment_method, $gateway->id, false ) . '>' . esc_html( $gateway->get_title() ) . '</option>';
301
												if ( $payment_method == $gateway->id ) {
302
													$found_method = true;
303
												}
304
											}
305
										}
306
307 View Code Duplication
										if ( ! $found_method && ! empty( $payment_method ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
308
											echo '<option value="' . esc_attr( $payment_method ) . '" selected="selected">' . __( 'Other', 'woocommerce' ) . '</option>';
309
										} else {
310
											echo '<option value="other">' . __( 'Other', 'woocommerce' ) . '</option>';
311
										}
312
									?>
313
								</select>
314
							</p>
315
							<?php
316
317
							woocommerce_wp_text_input( array( 'id' => '_transaction_id', 'label' => __( 'Transaction ID', 'woocommerce' ) ) );
318
319
							echo '</div>';
320
321
							do_action( 'woocommerce_admin_order_data_after_billing_address', $order );
322
						?>
323
					</div>
324
					<div class="order_data_column">
325
326
						<h3>
327
							<?php _e( 'Shipping Details', 'woocommerce' ); ?>
328
							<a href="#" class="edit_address"><?php _e( 'Edit', 'woocommerce' ); ?></a>
329
							<a href="#" class="tips billing-same-as-shipping" data-tip="<?php esc_attr_e( 'Copy from billing', 'woocommerce' ); ?>" style="display:none;"><?php _e( 'Copy from billing', 'woocommerce' ); ?></a>
330
							<a href="#" class="tips load_customer_shipping" data-tip="<?php esc_attr_e( 'Load shipping address', 'woocommerce' ); ?>" style="display:none;"><?php _e( 'Load shipping address', 'woocommerce' ); ?></a>
331
						</h3>
332
						<?php
333
							// Display values
334
							echo '<div class="address">';
335
336 View Code Duplication
								if ( $order->get_formatted_shipping_address() ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
337
									echo '<p><strong>' . __( 'Address', 'woocommerce' ) . ':</strong>' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '</p>';
338
								} else {
339
									echo '<p class="none_set"><strong>' . __( 'Address', 'woocommerce' ) . ':</strong> ' . __( 'No shipping address set.', 'woocommerce' ) . '</p>';
340
								}
341
342
								if ( ! empty( self::$shipping_fields ) ) {
343 View Code Duplication
									foreach ( self::$shipping_fields as $key => $field ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
344
										if ( isset( $field['show'] ) && false === $field['show'] ) {
345
											continue;
346
										}
347
348
										$field_name = 'shipping_' . $key;
349
350
										if ( ! empty( $order->$field_name ) ) {
351
											echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $order->$field_name ) ) . '</p>';
352
										}
353
									}
354
								}
355
356
								if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) {
357
									echo '<p><strong>' . __( 'Customer Provided Note', 'woocommerce' ) . ':</strong> ' . nl2br( esc_html( $post->post_excerpt ) ) . '</p>';
358
								}
359
360
							echo '</div>';
361
362
							// Display form
363
							echo '<div class="edit_address">';
364
365
							if ( ! empty( self::$shipping_fields ) ) {
366 View Code Duplication
								foreach ( self::$shipping_fields as $key => $field ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
367
									if ( ! isset( $field['type'] ) ) {
368
										$field['type'] = 'text';
369
									}
370
									if ( ! isset( $field['id'] ) ){
371
										$field['id'] = '_shipping_' . $key;
372
									}
373
374
									switch ( $field['type'] ) {
375
										case 'select' :
376
											woocommerce_wp_select( $field );
377
										break;
378
										default :
379
											woocommerce_wp_text_input( $field );
380
										break;
381
									}
382
								}
383
							}
384
385
							if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) {
386
								?>
387
								<p class="form-field form-field-wide"><label for="excerpt"><?php _e( 'Customer Provided Note', 'woocommerce' ) ?>:</label>
388
								<textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer\'s notes about the order', 'woocommerce' ); ?>"><?php echo wp_kses_post( $post->post_excerpt ); ?></textarea></p>
389
								<?php
390
							}
391
392
							echo '</div>';
393
394
							do_action( 'woocommerce_admin_order_data_after_shipping_address', $order );
395
						?>
396
					</div>
397
				</div>
398
				<div class="clear"></div>
399
			</div>
400
		</div>
401
		<?php
402
	}
403
404
	/**
405
	 * Save meta box data.
406
	 *
407
	 * @param int $post_id
408
	 * @param WP_Post $post
409
	 */
410
	public static function save( $post_id, $post ) {
411
		global $wpdb;
412
413
		self::init_address_fields();
414
415
		// Ensure gateways are loaded in case they need to insert data into the emails
416
		WC()->payment_gateways();
417
		WC()->shipping();
418
419
		$customer_changed = false;
420
421
		// Add key
422
		add_post_meta( $post_id, '_order_key', uniqid( 'order_' ), true );
423
424
		// Update meta
425
		if ( update_post_meta( $post_id, '_customer_user', absint( $_POST['customer_user'] ) ) ) {
426
			$customer_changed = true;
427
		}
428
429 View Code Duplication
		if ( ! empty( self::$billing_fields ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
430
			foreach ( self::$billing_fields as $key => $field ) {
431
				if ( ! isset( $field['id'] ) ){
432
					$field['id'] = '_billing_' . $key;
433
				}
434
				if ( update_post_meta( $post_id, $field['id'], wc_clean( $_POST[ $field['id'] ] ) ) ) {
435
					$customer_changed = true;
436
				}
437
			}
438
		}
439
440 View Code Duplication
		if ( ! empty( self::$shipping_fields ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
441
			foreach ( self::$shipping_fields as $key => $field ) {
442
				if ( ! isset( $field['id'] ) ){
443
					$field['id'] = '_shipping_' . $key;
444
				}
445
				if ( update_post_meta( $post_id, $field['id'], wc_clean( $_POST[ $field['id'] ] ) ) ) {
446
					$customer_changed = true;
447
				}
448
			}
449
		}
450
451
		if ( isset( $_POST['_transaction_id'] ) ) {
452
			update_post_meta( $post_id, '_transaction_id', wc_clean( $_POST[ '_transaction_id' ] ) );
453
		}
454
455
		// Payment method handling
456
		if ( get_post_meta( $post_id, '_payment_method', true ) !== stripslashes( $_POST['_payment_method'] ) ) {
457
458
			$methods              = WC()->payment_gateways->payment_gateways();
459
			$payment_method       = wc_clean( $_POST['_payment_method'] );
460
			$payment_method_title = $payment_method;
461
462
			if ( isset( $methods) && isset( $methods[ $payment_method ] ) ) {
463
				$payment_method_title = $methods[ $payment_method ]->get_title();
464
			}
465
466
			update_post_meta( $post_id, '_payment_method', $payment_method );
467
			update_post_meta( $post_id, '_payment_method_title', $payment_method_title );
468
		}
469
470
		// Update date
471
		if ( empty( $_POST['order_date'] ) ) {
472
			$date = current_time('timestamp');
473
		} else {
474
			$date = strtotime( $_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00' );
475
		}
476
477
		$date = date_i18n( 'Y-m-d H:i:s', $date );
478
479
		$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_date = %s, post_date_gmt = %s WHERE ID = %s", $date, get_gmt_from_date( $date ), $post_id ) );
480
481
		// If customer changed, update any downloadable permissions
482
		if ( $customer_changed ) {
483
			$wpdb->update( $wpdb->prefix . "woocommerce_downloadable_product_permissions",
484
				array(
485
					'user_id'    => absint( get_post_meta( $post->ID, '_customer_user', true ) ),
486
					'user_email' => wc_clean( get_post_meta( $post->ID, '_billing_email', true ) ),
487
				),
488
				array(
489
					'order_id' 		=> $post_id,
490
				),
491
				array(
492
					'%d',
493
					'%s',
494
				),
495
				array(
496
					'%d',
497
				)
498
			);
499
		}
500
501
		// Order data saved, now get it so we can manipulate status
502
		$order = wc_get_order( $post_id );
503
504
		// Order status
505
		$order->update_status( $_POST['order_status'], '', true );
506
507
		wc_delete_shop_order_transients( $post_id );
508
	}
509
}
510