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( 'label' => __( 'Country', 'woocommerce' ), 'show' => false, 'class' => 'js_field-country select short', 'type' => 'select', 'options' => array( '' => __( 'Select a country…', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(), ), '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( 'woocommerce_admin_shipping_fields', array( '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( 'label' => __( 'Country', 'woocommerce' ), 'show' => false, 'type' => 'select', 'class' => 'js_field-country select short', 'options' => array( '' => __( 'Select a country…', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(), ), 'state' => array( 'label' => __( 'State / County', 'woocommerce' ), 'class' => 'js_field-state select short', 'show' => false, ), ) ); } /** * Output the metabox. * * @param WP_Post $post */ public static function output( $post ) { global $theorder; if ( ! is_object( $theorder ) ) { $theorder = wc_get_order( $post->ID ); } $order = $theorder; self::init_address_fields(); if ( WC()->payment_gateways() ) { $payment_gateways = WC()->payment_gateways->payment_gateways(); } else { $payment_gateways = array(); } $payment_method = $order->get_payment_method(); $order_type_object = get_post_type_object( $post->post_type ); wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' ); ?>

labels->singular_name, $order->get_order_number() ); ?>

get_title() ) : esc_html( $payment_method ) ) ); if ( $transaction_id = $order->get_transaction_id() ) { if ( isset( $payment_gateways[ $payment_method ] ) && ( $url = $payment_gateways[ $payment_method ]->get_transaction_url( $order ) ) ) { echo ' (' . esc_html( $transaction_id ) . ')'; } else { echo ' (' . esc_html( $transaction_id ) . ')'; } } if ( $order->get_date_paid() ) { /* translators: 1: date 2: time */ printf( ' ' . __( 'on %1$s @ %2$s', 'woocommerce' ), wc_format_datetime( $order->get_date_paid() ), wc_format_datetime( $order->get_date_paid(), get_option( 'time_format' ) ) ); } echo '. '; } if ( $ip_address = $order->get_customer_ip_address() ) { /* translators: %s: IP address */ printf( __( 'Customer IP: %s', 'woocommerce' ), '' . esc_html( $ip_address ) . '' ); } ?>

@‎:

get_user_id() ) { $user_id = absint( $order->get_user_id() ); $user = get_user_by( 'id', $user_id ); /* translators: 1: user display name 2: user ID 3: user email */ $user_string = sprintf( esc_html__( '%1$s (#%2$s – %3$s)', 'woocommerce' ), $user->display_name, absint( $user->ID ), $user->user_email ); } ?>

'; if ( $order->get_formatted_billing_address() ) { echo '

' . __( 'Address:', 'woocommerce' ) . '' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '

'; } else { echo '

' . __( 'Address:', 'woocommerce' ) . ' ' . __( 'No billing address set.', 'woocommerce' ) . '

'; } foreach ( self::$billing_fields as $key => $field ) { if ( isset( $field['show'] ) && false === $field['show'] ) { continue; } $field_name = 'billing_' . $key; if ( is_callable( array( $order, 'get_' . $field_name ) ) ) { $field_value = $order->{"get_$field_name"}( 'edit' ); } else { $field_value = $order->get_meta( '_' . $field_name ); } if ( 'billing_phone' === $field_name ) { $field_value = wc_make_phone_clickable( $field_value ); } else { $field_value = make_clickable( esc_html( $field_value ) ); } echo '

' . esc_html( $field['label'] ) . ': ' . wp_kses_post( $field_value ) . '

'; } echo '
'; // Display form echo '
'; foreach ( self::$billing_fields as $key => $field ) { if ( ! isset( $field['type'] ) ) { $field['type'] = 'text'; } if ( ! isset( $field['id'] ) ) { $field['id'] = '_billing_' . $key; } switch ( $field['type'] ) { case 'select' : woocommerce_wp_select( $field ); break; default : woocommerce_wp_text_input( $field ); break; } } ?>

'_transaction_id', 'label' => __( 'Transaction ID', 'woocommerce' ) ) ); echo '
'; do_action( 'woocommerce_admin_order_data_after_billing_address', $order ); ?>

'; if ( $order->get_formatted_shipping_address() ) { echo '

' . __( 'Address:', 'woocommerce' ) . '' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '

'; } else { echo '

' . __( 'Address:', 'woocommerce' ) . ' ' . __( 'No shipping address set.', 'woocommerce' ) . '

'; } if ( ! empty( self::$shipping_fields ) ) { foreach ( self::$shipping_fields as $key => $field ) { if ( isset( $field['show'] ) && false === $field['show'] ) { continue; } $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 ); } echo '

' . esc_html( $field['label'] ) . ': ' . make_clickable( esc_html( $field_value ) ) . '

'; } } if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) { echo '

' . __( 'Customer provided note:', 'woocommerce' ) . ' ' . nl2br( esc_html( $post->post_excerpt ) ) . '

'; } echo '
'; // Display form echo '
'; if ( ! empty( self::$shipping_fields ) ) { foreach ( self::$shipping_fields as $key => $field ) { if ( ! isset( $field['type'] ) ) { $field['type'] = 'text'; } if ( ! isset( $field['id'] ) ) { $field['id'] = '_shipping_' . $key; } switch ( $field['type'] ) { case 'select' : woocommerce_wp_select( $field ); break; default : woocommerce_wp_text_input( $field ); break; } } } if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) { ?>

'; do_action( 'woocommerce_admin_order_data_after_shipping_address', $order ); ?>
payment_gateways(); WC()->shipping(); // Get order object. $order = wc_get_order( $order_id ); $props = array( 'status' => wc_clean( $_POST['order_status'] ) ); // Create order key. if ( ! $order->get_order_key() ) { $props['order_key'] = 'wc_' . apply_filters( 'woocommerce_generate_order_key', uniqid( 'order_' ) ); } // Update customer. $customer_id = isset( $_POST['customer_user'] ) ? absint( $_POST['customer_user'] ) : 0; if ( $customer_id !== $order->get_customer_id() ) { $props['customer_id'] = $customer_id; } // Update billing fields. if ( ! empty( self::$billing_fields ) ) { foreach ( self::$billing_fields as $key => $field ) { if ( ! isset( $field['id'] ) ) { $field['id'] = '_billing_' . $key; } if ( ! isset( $_POST[ $field['id'] ] ) ) { continue; } if ( is_callable( array( $order, 'set_billing_' . $key ) ) ) { $props[ 'billing_' . $key ] = wc_clean( $_POST[ $field['id'] ] ); } else { $order->update_meta_data( $field['id'], wc_clean( $_POST[ $field['id'] ] ) ); } } } // Update shipping fields. if ( ! empty( self::$shipping_fields ) ) { foreach ( self::$shipping_fields as $key => $field ) { if ( ! isset( $field['id'] ) ) { $field['id'] = '_shipping_' . $key; } if ( ! isset( $_POST[ $field['id'] ] ) ) { continue; } if ( is_callable( array( $order, 'set_shipping_' . $key ) ) ) { $props[ 'shipping_' . $key ] = wc_clean( $_POST[ $field['id'] ] ); } else { $order->update_meta_data( $field['id'], wc_clean( $_POST[ $field['id'] ] ) ); } } } if ( isset( $_POST['_transaction_id'] ) ) { $props['transaction_id'] = wc_clean( $_POST['_transaction_id'] ); } // Payment method handling. if ( $order->get_payment_method() !== wp_unslash( $_POST['_payment_method'] ) ) { $methods = WC()->payment_gateways->payment_gateways(); $payment_method = wc_clean( $_POST['_payment_method'] ); $payment_method_title = $payment_method; if ( isset( $methods ) && isset( $methods[ $payment_method ] ) ) { $payment_method_title = $methods[ $payment_method ]->get_title(); } $props['payment_method'] = $payment_method; $props['payment_method_title'] = $payment_method_title; } // Update date. if ( empty( $_POST['order_date'] ) ) { $date = current_time( 'timestamp', true ); } else { $date = gmdate( 'Y-m-d H:i:s', strtotime( $_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00' ) ); } $props['date_created'] = $date; // Save order data. $order->set_props( $props ); $order->save(); } }