class-wc-meta-box-order-data.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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. if ( ! defined( 'ABSPATH' ) ) {
  13. exit; // Exit if accessed directly
  14. }
  15. /**
  16. * WC_Meta_Box_Order_Data Class.
  17. */
  18. class WC_Meta_Box_Order_Data {
  19. /**
  20. * Billing fields.
  21. *
  22. * @var array
  23. */
  24. protected static $billing_fields = array();
  25. /**
  26. * Shipping fields.
  27. *
  28. * @var array
  29. */
  30. protected static $shipping_fields = array();
  31. /**
  32. * Init billing and shipping fields we display + save.
  33. */
  34. public static function init_address_fields() {
  35. self::$billing_fields = apply_filters(
  36. 'woocommerce_admin_billing_fields', array(
  37. 'first_name' => array(
  38. 'label' => __( 'First name', 'woocommerce' ),
  39. 'show' => false,
  40. ),
  41. 'last_name' => array(
  42. 'label' => __( 'Last name', 'woocommerce' ),
  43. 'show' => false,
  44. ),
  45. 'company' => array(
  46. 'label' => __( 'Company', 'woocommerce' ),
  47. 'show' => false,
  48. ),
  49. 'address_1' => array(
  50. 'label' => __( 'Address line 1', 'woocommerce' ),
  51. 'show' => false,
  52. ),
  53. 'address_2' => array(
  54. 'label' => __( 'Address line 2', 'woocommerce' ),
  55. 'show' => false,
  56. ),
  57. 'city' => array(
  58. 'label' => __( 'City', 'woocommerce' ),
  59. 'show' => false,
  60. ),
  61. 'postcode' => array(
  62. 'label' => __( 'Postcode / ZIP', 'woocommerce' ),
  63. 'show' => false,
  64. ),
  65. 'country' => array(
  66. 'label' => __( 'Country', 'woocommerce' ),
  67. 'show' => false,
  68. 'class' => 'js_field-country select short',
  69. 'type' => 'select',
  70. 'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(),
  71. ),
  72. 'state' => array(
  73. 'label' => __( 'State / County', 'woocommerce' ),
  74. 'class' => 'js_field-state select short',
  75. 'show' => false,
  76. ),
  77. 'email' => array(
  78. 'label' => __( 'Email address', 'woocommerce' ),
  79. ),
  80. 'phone' => array(
  81. 'label' => __( 'Phone', 'woocommerce' ),
  82. ),
  83. )
  84. );
  85. self::$shipping_fields = apply_filters(
  86. 'woocommerce_admin_shipping_fields', array(
  87. 'first_name' => array(
  88. 'label' => __( 'First name', 'woocommerce' ),
  89. 'show' => false,
  90. ),
  91. 'last_name' => array(
  92. 'label' => __( 'Last name', 'woocommerce' ),
  93. 'show' => false,
  94. ),
  95. 'company' => array(
  96. 'label' => __( 'Company', 'woocommerce' ),
  97. 'show' => false,
  98. ),
  99. 'address_1' => array(
  100. 'label' => __( 'Address line 1', 'woocommerce' ),
  101. 'show' => false,
  102. ),
  103. 'address_2' => array(
  104. 'label' => __( 'Address line 2', 'woocommerce' ),
  105. 'show' => false,
  106. ),
  107. 'city' => array(
  108. 'label' => __( 'City', 'woocommerce' ),
  109. 'show' => false,
  110. ),
  111. 'postcode' => array(
  112. 'label' => __( 'Postcode / ZIP', 'woocommerce' ),
  113. 'show' => false,
  114. ),
  115. 'country' => array(
  116. 'label' => __( 'Country', 'woocommerce' ),
  117. 'show' => false,
  118. 'type' => 'select',
  119. 'class' => 'js_field-country select short',
  120. 'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(),
  121. ),
  122. 'state' => array(
  123. 'label' => __( 'State / County', 'woocommerce' ),
  124. 'class' => 'js_field-state select short',
  125. 'show' => false,
  126. ),
  127. )
  128. );
  129. }
  130. /**
  131. * Output the metabox.
  132. *
  133. * @param WP_Post $post
  134. */
  135. public static function output( $post ) {
  136. global $theorder;
  137. if ( ! is_object( $theorder ) ) {
  138. $theorder = wc_get_order( $post->ID );
  139. }
  140. $order = $theorder;
  141. self::init_address_fields();
  142. if ( WC()->payment_gateways() ) {
  143. $payment_gateways = WC()->payment_gateways->payment_gateways();
  144. } else {
  145. $payment_gateways = array();
  146. }
  147. $payment_method = $order->get_payment_method();
  148. $order_type_object = get_post_type_object( $post->post_type );
  149. wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
  150. ?>
  151. <style type="text/css">
  152. #post-body-content, #titlediv { display:none }
  153. </style>
  154. <div class="panel-wrap woocommerce">
  155. <input name="post_title" type="hidden" value="<?php echo empty( $post->post_title ) ? __( 'Order', 'woocommerce' ) : esc_attr( $post->post_title ); ?>" />
  156. <input name="post_status" type="hidden" value="<?php echo esc_attr( $post->post_status ); ?>" />
  157. <div id="order_data" class="panel woocommerce-order-data">
  158. <h2 class="woocommerce-order-data__heading">
  159. <?php
  160. /* translators: 1: order type 2: order number */
  161. printf(
  162. esc_html__( '%1$s #%2$s details', 'woocommerce' ),
  163. esc_html( $order_type_object->labels->singular_name ),
  164. esc_html( $order->get_order_number() )
  165. );
  166. ?>
  167. </h2>
  168. <p class="woocommerce-order-data__meta order_number">
  169. <?php
  170. $meta_list = array();
  171. if ( $payment_method ) {
  172. /* translators: %s: payment method */
  173. $payment_method_string = sprintf(
  174. __( 'Payment via %s', 'woocommerce' ),
  175. esc_html( isset( $payment_gateways[ $payment_method ] ) ? $payment_gateways[ $payment_method ]->get_title() : $payment_method )
  176. );
  177. if ( $transaction_id = $order->get_transaction_id() ) {
  178. if ( isset( $payment_gateways[ $payment_method ] ) && ( $url = $payment_gateways[ $payment_method ]->get_transaction_url( $order ) ) ) {
  179. $payment_method_string .= ' (<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $transaction_id ) . '</a>)';
  180. } else {
  181. $payment_method_string .= ' (' . esc_html( $transaction_id ) . ')';
  182. }
  183. }
  184. $meta_list[] = $payment_method_string;
  185. }
  186. if ( $order->get_date_paid() ) {
  187. /* translators: 1: date 2: time */
  188. $meta_list[] = sprintf(
  189. __( 'Paid on %1$s @ %2$s', 'woocommerce' ),
  190. wc_format_datetime( $order->get_date_paid() ),
  191. wc_format_datetime( $order->get_date_paid(), get_option( 'time_format' ) )
  192. );
  193. }
  194. if ( $ip_address = $order->get_customer_ip_address() ) {
  195. /* translators: %s: IP address */
  196. $meta_list[] = sprintf(
  197. __( 'Customer IP: %s', 'woocommerce' ),
  198. '<span class="woocommerce-Order-customerIP">' . esc_html( $ip_address ) . '</span>'
  199. );
  200. }
  201. echo wp_kses_post( implode( '. ', $meta_list ) );
  202. ?>
  203. </p>
  204. <div class="order_data_column_container">
  205. <div class="order_data_column">
  206. <h3><?php esc_html_e( 'General', 'woocommerce' ); ?></h3>
  207. <p class="form-field form-field-wide">
  208. <label for="order_date"><?php _e( 'Date created:', 'woocommerce' ); ?></label>
  209. <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])' ) ); ?>" />@
  210. &lrm;
  211. <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})" />:
  212. <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}" />
  213. <input type="hidden" name="order_date_second" value="<?php echo esc_attr( date_i18n( 's', strtotime( $post->post_date ) ) ); ?>" />
  214. </p>
  215. <p class="form-field form-field-wide wc-order-status">
  216. <label for="order_status">
  217. <?php
  218. _e( 'Status:', 'woocommerce' );
  219. if ( $order->needs_payment() ) {
  220. printf(
  221. '<a href="%s">%s</a>',
  222. esc_url( $order->get_checkout_payment_url() ),
  223. __( 'Customer payment page &rarr;', 'woocommerce' )
  224. );
  225. }
  226. ?>
  227. </label>
  228. <select id="order_status" name="order_status" class="wc-enhanced-select">
  229. <?php
  230. $statuses = wc_get_order_statuses();
  231. foreach ( $statuses as $status => $status_name ) {
  232. echo '<option value="' . esc_attr( $status ) . '" ' . selected( $status, 'wc-' . $order->get_status( 'edit' ), false ) . '>' . esc_html( $status_name ) . '</option>';
  233. }
  234. ?>
  235. </select>
  236. </p>
  237. <p class="form-field form-field-wide wc-customer-user">
  238. <!--email_off--> <!-- Disable CloudFlare email obfuscation -->
  239. <label for="customer_user">
  240. <?php
  241. _e( 'Customer:', 'woocommerce' );
  242. if ( $order->get_user_id( 'edit' ) ) {
  243. $args = array(
  244. 'post_status' => 'all',
  245. 'post_type' => 'shop_order',
  246. '_customer_user' => $order->get_user_id( 'edit' ),
  247. );
  248. printf(
  249. '<a href="%s">%s</a>',
  250. esc_url( add_query_arg( $args, admin_url( 'edit.php' ) ) ),
  251. ' ' . __( 'View other orders &rarr;', 'woocommerce' )
  252. );
  253. printf(
  254. '<a href="%s">%s</a>',
  255. esc_url( add_query_arg( 'user_id', $order->get_user_id( 'edit' ), admin_url( 'user-edit.php' ) ) ),
  256. ' ' . __( 'Profile &rarr;', 'woocommerce' )
  257. );
  258. }
  259. ?>
  260. </label>
  261. <?php
  262. $user_string = '';
  263. $user_id = '';
  264. if ( $order->get_user_id() ) {
  265. $user_id = absint( $order->get_user_id() );
  266. $user = get_user_by( 'id', $user_id );
  267. /* translators: 1: user display name 2: user ID 3: user email */
  268. $user_string = sprintf(
  269. esc_html__( '%1$s (#%2$s &ndash; %3$s)', 'woocommerce' ),
  270. $user->display_name,
  271. absint( $user->ID ),
  272. $user->user_email
  273. );
  274. }
  275. ?>
  276. <select class="wc-customer-search" id="customer_user" name="customer_user" data-placeholder="<?php esc_attr_e( 'Guest', 'woocommerce' ); ?>" data-allow_clear="true">
  277. <option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo htmlspecialchars( $user_string ); ?></option>
  278. </select>
  279. <!--/email_off-->
  280. </p>
  281. <?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); ?>
  282. </div>
  283. <div class="order_data_column">
  284. <h3>
  285. <?php esc_html_e( 'Billing', 'woocommerce' ); ?>
  286. <a href="#" class="edit_address"><?php esc_html_e( 'Edit', 'woocommerce' ); ?></a>
  287. <span>
  288. <a href="#" class="load_customer_billing" style="display:none;"><?php esc_html_e( 'Load billing address', 'woocommerce' ); ?></a>
  289. </span>
  290. </h3>
  291. <div class="address">
  292. <?php
  293. // Display values.
  294. if ( $order->get_formatted_billing_address() ) {
  295. echo '<p>' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '</p>';
  296. } else {
  297. echo '<p class="none_set"><strong>' . __( 'Address:', 'woocommerce' ) . '</strong> ' . __( 'No billing address set.', 'woocommerce' ) . '</p>';
  298. }
  299. foreach ( self::$billing_fields as $key => $field ) {
  300. if ( isset( $field['show'] ) && false === $field['show'] ) {
  301. continue;
  302. }
  303. $field_name = 'billing_' . $key;
  304. if ( isset( $field['value'] ) ) {
  305. $field_value = $field['value'];
  306. } elseif ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
  307. $field_value = $order->{"get_$field_name"}( 'edit' );
  308. } else {
  309. $field_value = $order->get_meta( '_' . $field_name );
  310. }
  311. if ( 'billing_phone' === $field_name ) {
  312. $field_value = wc_make_phone_clickable( $field_value );
  313. } else {
  314. $field_value = make_clickable( esc_html( $field_value ) );
  315. }
  316. if ( $field_value ) {
  317. echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
  318. }
  319. }
  320. ?>
  321. </div>
  322. <div class="edit_address">
  323. <?php
  324. // Display form.
  325. foreach ( self::$billing_fields as $key => $field ) {
  326. if ( ! isset( $field['type'] ) ) {
  327. $field['type'] = 'text';
  328. }
  329. if ( ! isset( $field['id'] ) ) {
  330. $field['id'] = '_billing_' . $key;
  331. }
  332. $field_name = 'billing_' . $key;
  333. if ( ! isset( $field['value'] ) ) {
  334. if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
  335. $field['value'] = $order->{"get_$field_name"}( 'edit' );
  336. } else {
  337. $field['value'] = $order->get_meta( '_' . $field_name );
  338. }
  339. }
  340. switch ( $field['type'] ) {
  341. case 'select':
  342. woocommerce_wp_select( $field );
  343. break;
  344. default:
  345. woocommerce_wp_text_input( $field );
  346. break;
  347. }
  348. }
  349. ?>
  350. <p class="form-field form-field-wide">
  351. <label><?php esc_html_e( 'Payment method:', 'woocommerce' ); ?></label>
  352. <select name="_payment_method" id="_payment_method" class="first">
  353. <option value=""><?php esc_html_e( 'N/A', 'woocommerce' ); ?></option>
  354. <?php
  355. $found_method = false;
  356. foreach ( $payment_gateways as $gateway ) {
  357. if ( 'yes' === $gateway->enabled ) {
  358. echo '<option value="' . esc_attr( $gateway->id ) . '" ' . selected( $payment_method, $gateway->id, false ) . '>' . esc_html( $gateway->get_title() ) . '</option>';
  359. if ( $payment_method == $gateway->id ) {
  360. $found_method = true;
  361. }
  362. }
  363. }
  364. if ( ! $found_method && ! empty( $payment_method ) ) {
  365. echo '<option value="' . esc_attr( $payment_method ) . '" selected="selected">' . __( 'Other', 'woocommerce' ) . '</option>';
  366. } else {
  367. echo '<option value="other">' . __( 'Other', 'woocommerce' ) . '</option>';
  368. }
  369. ?>
  370. </select>
  371. </p>
  372. <?php
  373. woocommerce_wp_text_input(
  374. array(
  375. 'id' => '_transaction_id',
  376. 'label' => __( 'Transaction ID', 'woocommerce' ),
  377. 'value' => $order->get_transaction_id( 'edit' ),
  378. )
  379. );
  380. ?>
  381. </div>
  382. <?php do_action( 'woocommerce_admin_order_data_after_billing_address', $order ); ?>
  383. </div>
  384. <div class="order_data_column">
  385. <h3>
  386. <?php esc_html_e( 'Shipping', 'woocommerce' ); ?>
  387. <a href="#" class="edit_address"><?php esc_html_e( 'Edit', 'woocommerce' ); ?></a>
  388. <span>
  389. <a href="#" class="load_customer_shipping" style="display:none;"><?php esc_html_e( 'Load shipping address', 'woocommerce' ); ?></a>
  390. <a href="#" class="billing-same-as-shipping" style="display:none;"><?php esc_html_e( 'Copy billing address', 'woocommerce' ); ?></a>
  391. </span>
  392. </h3>
  393. <div class="address">
  394. <?php
  395. // Display values.
  396. if ( $order->get_formatted_shipping_address() ) {
  397. echo '<p>' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '</p>';
  398. } else {
  399. echo '<p class="none_set"><strong>' . __( 'Address:', 'woocommerce' ) . '</strong> ' . __( 'No shipping address set.', 'woocommerce' ) . '</p>';
  400. }
  401. if ( ! empty( self::$shipping_fields ) ) {
  402. foreach ( self::$shipping_fields as $key => $field ) {
  403. if ( isset( $field['show'] ) && false === $field['show'] ) {
  404. continue;
  405. }
  406. $field_name = 'shipping_' . $key;
  407. if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
  408. $field_value = $order->{"get_$field_name"}( 'edit' );
  409. } else {
  410. $field_value = $order->get_meta( '_' . $field_name );
  411. }
  412. if ( $field_value ) {
  413. echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
  414. }
  415. }
  416. }
  417. if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) {
  418. echo '<p class="order_note"><strong>' . __( 'Customer provided note:', 'woocommerce' ) . '</strong> ' . nl2br( esc_html( $post->post_excerpt ) ) . '</p>';
  419. }
  420. ?>
  421. </div>
  422. <div class="edit_address">
  423. <?php
  424. // Display form.
  425. if ( ! empty( self::$shipping_fields ) ) {
  426. foreach ( self::$shipping_fields as $key => $field ) {
  427. if ( ! isset( $field['type'] ) ) {
  428. $field['type'] = 'text';
  429. }
  430. if ( ! isset( $field['id'] ) ) {
  431. $field['id'] = '_shipping_' . $key;
  432. }
  433. $field_name = 'shipping_' . $key;
  434. if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
  435. $field['value'] = $order->{"get_$field_name"}( 'edit' );
  436. } else {
  437. $field['value'] = $order->get_meta( '_' . $field_name );
  438. }
  439. switch ( $field['type'] ) {
  440. case 'select':
  441. woocommerce_wp_select( $field );
  442. break;
  443. default:
  444. woocommerce_wp_text_input( $field );
  445. break;
  446. }
  447. }
  448. }
  449. if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) :
  450. ?>
  451. <p class="form-field form-field-wide">
  452. <label for="excerpt"><?php _e( 'Customer provided note', 'woocommerce' ); ?>:</label>
  453. <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>
  454. </p>
  455. <?php endif; ?>
  456. </div>
  457. <?php do_action( 'woocommerce_admin_order_data_after_shipping_address', $order ); ?>
  458. </div>
  459. </div>
  460. <div class="clear"></div>
  461. </div>
  462. </div>
  463. <?php
  464. }
  465. /**
  466. * Save meta box data.
  467. *
  468. * @param int $order_id Order ID.
  469. */
  470. public static function save( $order_id ) {
  471. self::init_address_fields();
  472. // Ensure gateways are loaded in case they need to insert data into the emails.
  473. WC()->payment_gateways();
  474. WC()->shipping();
  475. // Get order object.
  476. $order = wc_get_order( $order_id );
  477. $props = array();
  478. // Create order key.
  479. if ( ! $order->get_order_key() ) {
  480. $props['order_key'] = 'wc_' . apply_filters( 'woocommerce_generate_order_key', uniqid( 'order_' ) );
  481. }
  482. // Update customer.
  483. $customer_id = isset( $_POST['customer_user'] ) ? absint( $_POST['customer_user'] ) : 0;
  484. if ( $customer_id !== $order->get_customer_id() ) {
  485. $props['customer_id'] = $customer_id;
  486. }
  487. // Update billing fields.
  488. if ( ! empty( self::$billing_fields ) ) {
  489. foreach ( self::$billing_fields as $key => $field ) {
  490. if ( ! isset( $field['id'] ) ) {
  491. $field['id'] = '_billing_' . $key;
  492. }
  493. if ( ! isset( $_POST[ $field['id'] ] ) ) {
  494. continue;
  495. }
  496. if ( is_callable( array( $order, 'set_billing_' . $key ) ) ) {
  497. $props[ 'billing_' . $key ] = wc_clean( $_POST[ $field['id'] ] );
  498. } else {
  499. $order->update_meta_data( $field['id'], wc_clean( $_POST[ $field['id'] ] ) );
  500. }
  501. }
  502. }
  503. // Update shipping fields.
  504. if ( ! empty( self::$shipping_fields ) ) {
  505. foreach ( self::$shipping_fields as $key => $field ) {
  506. if ( ! isset( $field['id'] ) ) {
  507. $field['id'] = '_shipping_' . $key;
  508. }
  509. if ( ! isset( $_POST[ $field['id'] ] ) ) {
  510. continue;
  511. }
  512. if ( is_callable( array( $order, 'set_shipping_' . $key ) ) ) {
  513. $props[ 'shipping_' . $key ] = wc_clean( $_POST[ $field['id'] ] );
  514. } else {
  515. $order->update_meta_data( $field['id'], wc_clean( $_POST[ $field['id'] ] ) );
  516. }
  517. }
  518. }
  519. if ( isset( $_POST['_transaction_id'] ) ) {
  520. $props['transaction_id'] = wc_clean( $_POST['_transaction_id'] );
  521. }
  522. // Payment method handling.
  523. if ( $order->get_payment_method() !== wp_unslash( $_POST['_payment_method'] ) ) {
  524. $methods = WC()->payment_gateways->payment_gateways();
  525. $payment_method = wc_clean( $_POST['_payment_method'] );
  526. $payment_method_title = $payment_method;
  527. if ( isset( $methods ) && isset( $methods[ $payment_method ] ) ) {
  528. $payment_method_title = $methods[ $payment_method ]->get_title();
  529. }
  530. $props['payment_method'] = $payment_method;
  531. $props['payment_method_title'] = $payment_method_title;
  532. }
  533. // Update date.
  534. if ( empty( $_POST['order_date'] ) ) {
  535. $date = current_time( 'timestamp', true );
  536. } else {
  537. $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'] ) );
  538. }
  539. $props['date_created'] = $date;
  540. // Set created via prop if new post.
  541. if ( isset( $_POST['original_post_status'] ) && $_POST['original_post_status'] === 'auto-draft' ) {
  542. $props['created_via'] = 'admin';
  543. }
  544. // Save order data.
  545. $order->set_props( $props );
  546. $order->set_status( wc_clean( $_POST['order_status'] ), '', true );
  547. $order->save();
  548. }
  549. }