1
|
|
|
<?php |
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…', '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…', '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
|
|
|
|
183
|
|
|
if ( $order->paid_date ) { |
184
|
|
|
printf( ' ' . _x( 'on %s @ %s', 'on date at time', 'woocommerce' ), date_i18n( get_option( 'date_format' ), strtotime( $order->paid_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $order->paid_date ) ) ); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
echo '. '; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
View Code Duplication |
if ( $ip_address = get_post_meta( $post->ID, '_customer_ip_address', true ) ) { |
|
|
|
|
191
|
|
|
echo __( 'Customer IP', 'woocommerce' ) . ': <span class="woocommerce-Order-customerIP">' . esc_html( $ip_address ) . '</span>'; |
192
|
|
|
} |
193
|
|
|
?></p> |
194
|
|
|
|
195
|
|
|
<div class="order_data_column_container"> |
196
|
|
|
<div class="order_data_column"> |
197
|
|
|
<h3><?php _e( 'General Details', 'woocommerce' ); ?></h3> |
198
|
|
|
|
199
|
|
|
<p class="form-field form-field-wide"><label for="order_date"><?php _e( 'Order date:', 'woocommerce' ) ?></label> |
200
|
|
|
<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,})?" /> |
201
|
|
|
</p> |
202
|
|
|
|
203
|
|
|
<p class="form-field form-field-wide wc-order-status"><label for="order_status"><?php _e( 'Order status:', 'woocommerce' ) ?> <?php |
204
|
|
|
if ( $order->has_status( 'pending' ) ) { |
205
|
|
|
printf( '<a href="%s">%s →</a>', |
206
|
|
|
esc_url( $order->get_checkout_payment_url() ), |
207
|
|
|
__( 'Customer payment page', 'woocommerce' ) |
208
|
|
|
); |
209
|
|
|
} |
210
|
|
|
?></label> |
211
|
|
|
<select id="order_status" name="order_status" class="wc-enhanced-select"> |
212
|
|
|
<?php |
213
|
|
|
$statuses = wc_get_order_statuses(); |
214
|
|
|
foreach ( $statuses as $status => $status_name ) { |
215
|
|
|
echo '<option value="' . esc_attr( $status ) . '" ' . selected( $status, 'wc-' . $order->get_status(), false ) . '>' . esc_html( $status_name ) . '</option>'; |
216
|
|
|
} |
217
|
|
|
?> |
218
|
|
|
</select></p> |
219
|
|
|
|
220
|
|
|
<p class="form-field form-field-wide wc-customer-user"> |
221
|
|
|
<label for="customer_user"><?php _e( 'Customer:', 'woocommerce' ) ?> <?php |
222
|
|
|
if ( ! empty( $order->customer_user ) ) { |
223
|
|
|
$args = array( 'post_status' => 'all', |
224
|
|
|
'post_type' => 'shop_order', |
225
|
|
|
'_customer_user' => absint( $order->customer_user ) |
226
|
|
|
); |
227
|
|
|
printf( '<a href="%s">%s →</a>', |
228
|
|
|
esc_url( add_query_arg( $args, admin_url( 'edit.php' ) ) ), |
229
|
|
|
__( 'View other orders', 'woocommerce' ) |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
?></label> |
233
|
|
|
<?php |
234
|
|
|
$user_string = ''; |
235
|
|
|
$user_id = ''; |
236
|
|
|
if ( ! empty( $order->customer_user ) ) { |
237
|
|
|
$user_id = absint( $order->customer_user ); |
238
|
|
|
$user = get_user_by( 'id', $user_id ); |
239
|
|
|
$user_string = esc_html( $user->display_name ) . ' (#' . absint( $user->ID ) . ' – ' . esc_html( $user->user_email ) . ')'; |
240
|
|
|
} |
241
|
|
|
?> |
242
|
|
|
<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" /> |
243
|
|
|
</p> |
244
|
|
|
<?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); ?> |
245
|
|
|
</div> |
246
|
|
|
<div class="order_data_column"> |
247
|
|
|
<h3> |
248
|
|
|
<?php _e( 'Billing Details', 'woocommerce' ); ?> |
249
|
|
|
<a href="#" class="edit_address"><?php _e( 'Edit', 'woocommerce' ); ?></a> |
250
|
|
|
<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> |
251
|
|
|
</h3> |
252
|
|
|
<?php |
253
|
|
|
// Display values |
254
|
|
|
echo '<div class="address">'; |
255
|
|
|
|
256
|
|
View Code Duplication |
if ( $order->get_formatted_billing_address() ) { |
|
|
|
|
257
|
|
|
echo '<p><strong>' . __( 'Address', 'woocommerce' ) . ':</strong>' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '</p>'; |
258
|
|
|
} else { |
259
|
|
|
echo '<p class="none_set"><strong>' . __( 'Address', 'woocommerce' ) . ':</strong> ' . __( 'No billing address set.', 'woocommerce' ) . '</p>'; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
View Code Duplication |
foreach ( self::$billing_fields as $key => $field ) { |
|
|
|
|
263
|
|
|
if ( isset( $field['show'] ) && false === $field['show'] ) { |
264
|
|
|
continue; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
$field_name = 'billing_' . $key; |
268
|
|
|
|
269
|
|
|
if ( $order->$field_name ) { |
270
|
|
|
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $order->$field_name ) ) . '</p>'; |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
echo '</div>'; |
275
|
|
|
|
276
|
|
|
// Display form |
277
|
|
|
echo '<div class="edit_address">'; |
278
|
|
|
|
279
|
|
View Code Duplication |
foreach ( self::$billing_fields as $key => $field ) { |
|
|
|
|
280
|
|
|
if ( ! isset( $field['type'] ) ) { |
281
|
|
|
$field['type'] = 'text'; |
282
|
|
|
} |
283
|
|
|
if ( ! isset( $field['id'] ) ){ |
284
|
|
|
$field['id'] = '_billing_' . $key; |
285
|
|
|
} |
286
|
|
|
switch ( $field['type'] ) { |
287
|
|
|
case 'select' : |
288
|
|
|
woocommerce_wp_select( $field ); |
289
|
|
|
break; |
290
|
|
|
default : |
291
|
|
|
woocommerce_wp_text_input( $field ); |
292
|
|
|
break; |
293
|
|
|
} |
294
|
|
|
} |
295
|
|
|
?> |
296
|
|
|
<p class="form-field form-field-wide"> |
297
|
|
|
<label><?php _e( 'Payment Method:', 'woocommerce' ); ?></label> |
298
|
|
|
<select name="_payment_method" id="_payment_method" class="first"> |
299
|
|
|
<option value=""><?php _e( 'N/A', 'woocommerce' ); ?></option> |
300
|
|
|
<?php |
301
|
|
|
$found_method = false; |
302
|
|
|
|
303
|
|
|
foreach ( $payment_gateways as $gateway ) { |
304
|
|
|
if ( $gateway->enabled == "yes" ) { |
305
|
|
|
echo '<option value="' . esc_attr( $gateway->id ) . '" ' . selected( $payment_method, $gateway->id, false ) . '>' . esc_html( $gateway->get_title() ) . '</option>'; |
306
|
|
|
if ( $payment_method == $gateway->id ) { |
307
|
|
|
$found_method = true; |
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
|
312
|
|
View Code Duplication |
if ( ! $found_method && ! empty( $payment_method ) ) { |
|
|
|
|
313
|
|
|
echo '<option value="' . esc_attr( $payment_method ) . '" selected="selected">' . __( 'Other', 'woocommerce' ) . '</option>'; |
314
|
|
|
} else { |
315
|
|
|
echo '<option value="other">' . __( 'Other', 'woocommerce' ) . '</option>'; |
316
|
|
|
} |
317
|
|
|
?> |
318
|
|
|
</select> |
319
|
|
|
</p> |
320
|
|
|
<?php |
321
|
|
|
|
322
|
|
|
woocommerce_wp_text_input( array( 'id' => '_transaction_id', 'label' => __( 'Transaction ID', 'woocommerce' ) ) ); |
323
|
|
|
|
324
|
|
|
echo '</div>'; |
325
|
|
|
|
326
|
|
|
do_action( 'woocommerce_admin_order_data_after_billing_address', $order ); |
327
|
|
|
?> |
328
|
|
|
</div> |
329
|
|
|
<div class="order_data_column"> |
330
|
|
|
|
331
|
|
|
<h3> |
332
|
|
|
<?php _e( 'Shipping Details', 'woocommerce' ); ?> |
333
|
|
|
<a href="#" class="edit_address"><?php _e( 'Edit', 'woocommerce' ); ?></a> |
334
|
|
|
<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> |
335
|
|
|
<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> |
336
|
|
|
</h3> |
337
|
|
|
<?php |
338
|
|
|
// Display values |
339
|
|
|
echo '<div class="address">'; |
340
|
|
|
|
341
|
|
View Code Duplication |
if ( $order->get_formatted_shipping_address() ) { |
|
|
|
|
342
|
|
|
echo '<p><strong>' . __( 'Address', 'woocommerce' ) . ':</strong>' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '</p>'; |
343
|
|
|
} else { |
344
|
|
|
echo '<p class="none_set"><strong>' . __( 'Address', 'woocommerce' ) . ':</strong> ' . __( 'No shipping address set.', 'woocommerce' ) . '</p>'; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
if ( ! empty( self::$shipping_fields ) ) { |
348
|
|
View Code Duplication |
foreach ( self::$shipping_fields as $key => $field ) { |
|
|
|
|
349
|
|
|
if ( isset( $field['show'] ) && false === $field['show'] ) { |
350
|
|
|
continue; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
$field_name = 'shipping_' . $key; |
354
|
|
|
|
355
|
|
|
if ( ! empty( $order->$field_name ) ) { |
356
|
|
|
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $order->$field_name ) ) . '</p>'; |
357
|
|
|
} |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) { |
362
|
|
|
echo '<p><strong>' . __( 'Customer Provided Note', 'woocommerce' ) . ':</strong> ' . nl2br( esc_html( $post->post_excerpt ) ) . '</p>'; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
echo '</div>'; |
366
|
|
|
|
367
|
|
|
// Display form |
368
|
|
|
echo '<div class="edit_address">'; |
369
|
|
|
|
370
|
|
|
if ( ! empty( self::$shipping_fields ) ) { |
371
|
|
View Code Duplication |
foreach ( self::$shipping_fields as $key => $field ) { |
|
|
|
|
372
|
|
|
if ( ! isset( $field['type'] ) ) { |
373
|
|
|
$field['type'] = 'text'; |
374
|
|
|
} |
375
|
|
|
if ( ! isset( $field['id'] ) ){ |
376
|
|
|
$field['id'] = '_shipping_' . $key; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
switch ( $field['type'] ) { |
380
|
|
|
case 'select' : |
381
|
|
|
woocommerce_wp_select( $field ); |
382
|
|
|
break; |
383
|
|
|
default : |
384
|
|
|
woocommerce_wp_text_input( $field ); |
385
|
|
|
break; |
386
|
|
|
} |
387
|
|
|
} |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) { |
391
|
|
|
?> |
392
|
|
|
<p class="form-field form-field-wide"><label for="excerpt"><?php _e( 'Customer Provided Note', 'woocommerce' ) ?>:</label> |
393
|
|
|
<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> |
394
|
|
|
<?php |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
echo '</div>'; |
398
|
|
|
|
399
|
|
|
do_action( 'woocommerce_admin_order_data_after_shipping_address', $order ); |
400
|
|
|
?> |
401
|
|
|
</div> |
402
|
|
|
</div> |
403
|
|
|
<div class="clear"></div> |
404
|
|
|
</div> |
405
|
|
|
</div> |
406
|
|
|
<?php |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* Save meta box data. |
411
|
|
|
* |
412
|
|
|
* @param int $post_id |
413
|
|
|
* @param WP_Post $post |
414
|
|
|
*/ |
415
|
|
|
public static function save( $post_id, $post ) { |
416
|
|
|
global $wpdb; |
417
|
|
|
|
418
|
|
|
self::init_address_fields(); |
419
|
|
|
|
420
|
|
|
// Ensure gateways are loaded in case they need to insert data into the emails |
421
|
|
|
WC()->payment_gateways(); |
422
|
|
|
WC()->shipping(); |
423
|
|
|
|
424
|
|
|
$customer_changed = false; |
425
|
|
|
|
426
|
|
|
// Add key |
427
|
|
|
add_post_meta( $post_id, '_order_key', uniqid( 'order_' ), true ); |
428
|
|
|
|
429
|
|
|
// Update meta |
430
|
|
|
if ( update_post_meta( $post_id, '_customer_user', absint( $_POST['customer_user'] ) ) ) { |
431
|
|
|
$customer_changed = true; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
View Code Duplication |
if ( ! empty( self::$billing_fields ) ) { |
|
|
|
|
435
|
|
|
foreach ( self::$billing_fields as $key => $field ) { |
436
|
|
|
if ( ! isset( $field['id'] ) ){ |
437
|
|
|
$field['id'] = '_billing_' . $key; |
438
|
|
|
} |
439
|
|
|
if ( update_post_meta( $post_id, $field['id'], wc_clean( $_POST[ $field['id'] ] ) ) ) { |
440
|
|
|
$customer_changed = true; |
441
|
|
|
} |
442
|
|
|
} |
443
|
|
|
} |
444
|
|
|
|
445
|
|
View Code Duplication |
if ( ! empty( self::$shipping_fields ) ) { |
|
|
|
|
446
|
|
|
foreach ( self::$shipping_fields as $key => $field ) { |
447
|
|
|
if ( ! isset( $field['id'] ) ){ |
448
|
|
|
$field['id'] = '_shipping_' . $key; |
449
|
|
|
} |
450
|
|
|
if ( update_post_meta( $post_id, $field['id'], wc_clean( $_POST[ $field['id'] ] ) ) ) { |
451
|
|
|
$customer_changed = true; |
452
|
|
|
} |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
if ( isset( $_POST['_transaction_id'] ) ) { |
457
|
|
|
update_post_meta( $post_id, '_transaction_id', wc_clean( $_POST[ '_transaction_id' ] ) ); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
// Payment method handling |
461
|
|
|
if ( get_post_meta( $post_id, '_payment_method', true ) !== stripslashes( $_POST['_payment_method'] ) ) { |
462
|
|
|
|
463
|
|
|
$methods = WC()->payment_gateways->payment_gateways(); |
464
|
|
|
$payment_method = wc_clean( $_POST['_payment_method'] ); |
465
|
|
|
$payment_method_title = $payment_method; |
466
|
|
|
|
467
|
|
|
if ( isset( $methods) && isset( $methods[ $payment_method ] ) ) { |
468
|
|
|
$payment_method_title = $methods[ $payment_method ]->get_title(); |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
update_post_meta( $post_id, '_payment_method', $payment_method ); |
472
|
|
|
update_post_meta( $post_id, '_payment_method_title', $payment_method_title ); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
// Update date |
476
|
|
|
if ( empty( $_POST['order_date'] ) ) { |
477
|
|
|
$date = current_time('timestamp'); |
478
|
|
|
} else { |
479
|
|
|
$date = strtotime( $_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00' ); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
$date = date_i18n( 'Y-m-d H:i:s', $date ); |
483
|
|
|
|
484
|
|
|
$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 ) ); |
485
|
|
|
|
486
|
|
|
clean_post_cache( $post_id ); |
487
|
|
|
|
488
|
|
|
// If customer changed, update any downloadable permissions |
489
|
|
|
if ( $customer_changed ) { |
490
|
|
|
$wpdb->update( $wpdb->prefix . "woocommerce_downloadable_product_permissions", |
491
|
|
|
array( |
492
|
|
|
'user_id' => absint( get_post_meta( $post->ID, '_customer_user', true ) ), |
493
|
|
|
'user_email' => wc_clean( get_post_meta( $post->ID, '_billing_email', true ) ), |
494
|
|
|
), |
495
|
|
|
array( |
496
|
|
|
'order_id' => $post_id, |
497
|
|
|
), |
498
|
|
|
array( |
499
|
|
|
'%d', |
500
|
|
|
'%s', |
501
|
|
|
), |
502
|
|
|
array( |
503
|
|
|
'%d', |
504
|
|
|
) |
505
|
|
|
); |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
// Order data saved, now get it so we can manipulate status |
509
|
|
|
$order = wc_get_order( $post_id ); |
510
|
|
|
|
511
|
|
|
// Order status |
512
|
|
|
$order->update_status( $_POST['order_status'], '', true ); |
513
|
|
|
|
514
|
|
|
wc_delete_shop_order_transients( $post_id ); |
515
|
|
|
} |
516
|
|
|
} |
517
|
|
|
|
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.