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 / Region', 'woocommerce' ),
					'show'    => false,
					'class'   => 'js_field-country select short',
					'type'    => 'select',
					'options' => array( '' => __( 'Select a country / region…', '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' ),
				),
			),
			$order,
			$context
		);
	}
	/**
	 * Get shipping fields for the meta box.
	 *
	 * @param \WC_Order $order Order object.
	 * @param string    $context Context of fields (view or edit).
	 * @return array
	 */
	protected static function get_shipping_fields( $order = false, $context = 'edit' ) {
		/**
		 * Provides an opportunity to modify the list of order shipping fields displayed on the admin.
		 *
		 * @since 1.4.0
		 *
		 * @param array Shipping fields.
		 * @param WC_Order|false $order Order object.
		 * @param string $context Context of fields (view or edit).
		 */
		return 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 / Region', 'woocommerce' ),
					'show'    => false,
					'type'    => 'select',
					'class'   => 'js_field-country select short',
					'options' => array( '' => __( 'Select a country / region…', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(),
				),
				'state'      => array(
					'label' => __( 'State / County', 'woocommerce' ),
					'class' => 'js_field-state select short',
					'show'  => false,
				),
				'phone'      => array(
					'label' => __( 'Phone', 'woocommerce' ),
				),
			),
			$order,
			$context
		);
	}
	/**
	 * Init billing and shipping fields we display + save. Maintained for backwards compat.
	 */
	public static function init_address_fields() {
		self::$billing_fields  = self::get_billing_fields();
		self::$shipping_fields = self::get_shipping_fields();
	}
	/**
	 * Output the metabox.
	 *
	 * @param WP_Post|WC_Order $post Post or order object.
	 */
	public static function output( $post ) {
		global $theorder;
		OrderUtil::init_theorder_object( $post );
		$order = $theorder;
		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( $order->get_type() );
		wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
		?>
		
		
			
			
			
				
					labels->singular_name ),
						esc_html( $order->get_order_number() )
					);
					?>
				
				
					get_title() : $payment_method )
						);
						$transaction_id = $order->get_transaction_id();
						if ( $transaction_id ) {
							$to_add = null;
							if ( isset( $payment_gateways[ $payment_method ] ) ) {
								$url = $payment_gateways[ $payment_method ]->get_transaction_url( $order );
								if ( $url ) {
									$to_add .= ' (' . esc_html( $transaction_id ) . ')';
								}
							}
							$to_add                 = $to_add ?? ' (' . esc_html( $transaction_id ) . ')';
							$payment_method_string .= $to_add;
						}
						$meta_list[] = $payment_method_string;
					}
					if ( $order->get_date_paid() ) {
						$meta_list[] = sprintf(
							/* translators: 1: date 2: time */
							__( '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' ) )
						);
					}
					$ip_address = $order->get_customer_ip_address();
					if ( $ip_address ) {
						$meta_list[] = sprintf(
							/* translators: %s: IP address */
							__( 'Customer IP: %s', 'woocommerce' ),
							'' . esc_html( $ip_address ) . ''
						);
					}
					echo wp_kses_post( implode( '. ', $meta_list ) );
					?>
				
				
				
					
						
						
							get_date_created() ) ? $order->get_date_created()->getOffsetTimestamp() : '';
							?>
							
							@
							
							:
							
							
						
						
							
							
						
						
							 
							
							get_user_id() ) {
								$user_id  = absint( $order->get_user_id() );
								$customer = new WC_Customer( $user_id );
								/* translators: 1: user display name 2: user ID 3: user email */
								$user_string = sprintf(
									/* translators: 1: customer name, 2 customer id, 3: customer email */
									esc_html__( '%1$s (#%2$s – %3$s)', 'woocommerce' ),
									$customer->get_first_name() . ' ' . $customer->get_last_name(),
									$customer->get_id(),
									$customer->get_email()
								);
							}
							?>
							
							
						
						
					 
					
						
							
							
							
								
							
						
						
							get_formatted_billing_address() ) {
								echo '
' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '
';
							} else {
								echo '
' . esc_html__( 'Address:', 'woocommerce' ) . ' ' . esc_html__( 'No billing address set.', 'woocommerce' ) . '
';
							}
							$billing_fields = self::get_billing_fields( $order, 'view' );
							foreach ( $billing_fields as $key => $field ) {
								if ( isset( $field['show'] ) && false === $field['show'] ) {
									continue;
								}
								$field_name = 'billing_' . $key;
								if ( isset( $field['value'] ) ) {
									$field_value = $field['value'];
								} elseif ( 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 );
								} elseif ( 'billing_email' === $field_name ) {
									$field_value = '
' . $field_value . '';
								} else {
									$field_value = make_clickable( esc_html( $field_value ) );
								}
								if ( $field_value ) {
									echo '
' . esc_html( $field['label'] ) . ': ' . wp_kses_post( $field_value ) . '
';
								}
							}
							?>
						
							 $field ) {
								if ( ! isset( $field['type'] ) ) {
									$field['type'] = 'text';
								}
								if ( ! isset( $field['id'] ) ) {
									$field['id'] = '_billing_' . $key;
								}
								$field_name = 'billing_' . $key;
								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 );
									}
								}
								switch ( $field['type'] ) {
									case 'select':
										woocommerce_wp_select( $field, $order );
										break;
									case 'checkbox':
										woocommerce_wp_checkbox( $field, $order );
										break;
									default:
										woocommerce_wp_text_input( $field, $order );
										break;
								}
							}
							?>
							
								
								
							
							 '_transaction_id',
									'label' => __( 'Transaction ID', 'woocommerce' ),
									'value' => $order->get_transaction_id( 'edit' ),
								),
								$order
							);
							?>
						
 
					
						
							
							
							
								
								
							
						
						
							get_formatted_shipping_address() ) {
								echo '
' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '
';
							} else {
								echo '
' . esc_html__( 'Address:', 'woocommerce' ) . ' ' . esc_html__( 'No shipping address set.', 'woocommerce' ) . '
';
							}
							$shipping_fields = self::get_shipping_fields( $order, 'view' );
							if ( ! empty( $shipping_fields ) ) {
								foreach ( $shipping_fields as $key => $field ) {
									if ( isset( $field['show'] ) && false === $field['show'] ) {
										continue;
									}
									$field_name = 'shipping_' . $key;
									if ( isset( $field['value'] ) ) {
										$field_value = $field['value'];
									} elseif ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
										$field_value = $order->{"get_$field_name"}( 'edit' );
									} else {
										$field_value = $order->get_meta( '_' . $field_name );
									}
									if ( 'shipping_phone' === $field_name ) {
										$field_value = wc_make_phone_clickable( $field_value );
									}
									if ( ! $field_value ) {
										continue;
									}
									echo '
' . esc_html( $field['label'] ) . ': ' . wp_kses_post( $field_value ) . '
';
								}
							}
							if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $order->get_customer_note() ) { // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
								echo '
' . esc_html( __( 'Customer provided note:', 'woocommerce' ) ) . ' ' . wp_kses( nl2br( esc_html( $order->get_customer_note() ) ), array() ) . '
';
							}
							?>
						
							 $field ) {
									if ( ! isset( $field['type'] ) ) {
										$field['type'] = 'text';
									}
									if ( ! isset( $field['id'] ) ) {
										$field['id'] = '_shipping_' . $key;
									}
									$field_name = 'shipping_' . $key;
									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 );
										}
									}
									switch ( $field['type'] ) {
										case 'select':
											woocommerce_wp_select( $field, $order );
											break;
										case 'checkbox':
											woocommerce_wp_checkbox( $field, $order );
											break;
										default:
											woocommerce_wp_text_input( $field, $order );
											break;
									}
								}
							}
							/**
							 * Allows 3rd parties to alter whether the customer note should be displayed on the admin.
							 *
							 * @since 2.1.0
							 *
							 * @param bool TRUE if the note should be displayed. FALSE otherwise.
							 */
							if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) :
								?>
								
									
									
								
							
						 
				 
				
			 
		 
		payment_gateways();
		WC()->shipping();
		// Get order object.
		$order = wc_get_order( $order_id );
		$props = array();
		// Create order key.
		if ( ! $order->get_order_key() ) {
			$props['order_key'] = wc_generate_order_key();
		}
		// 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.
		$billing_fields = self::get_billing_fields( $order, 'edit' );
		if ( ! empty( $billing_fields ) ) {
			foreach ( $billing_fields as $key => $field ) {
				if ( ! isset( $field['id'] ) ) {
					$field['id'] = '_billing_' . $key;
				}
				if ( ! isset( $_POST[ $field['id'] ] ) ) {
					continue;
				}
				$value = wc_clean( wp_unslash( $_POST[ $field['id'] ] ) );
				// Update a field if it includes an update callback.
				if ( isset( $field['update_callback'] ) ) {
					call_user_func( $field['update_callback'], $field['id'], $value, $order );
				} elseif ( is_callable( array( $order, 'set_billing_' . $key ) ) ) {
					$props[ 'billing_' . $key ] = $value;
				} else {
					$order->update_meta_data( $field['id'], $value );
				}
			}
		}
		// Update shipping fields.
		$shipping_fields = self::get_shipping_fields( $order, 'edit' );
		if ( ! empty( $shipping_fields ) ) {
			foreach ( $shipping_fields as $key => $field ) {
				if ( ! isset( $field['id'] ) ) {
					$field['id'] = '_shipping_' . $key;
				}
				if ( ! isset( $_POST[ $field['id'] ] ) ) {
					continue;
				}
				$value = isset( $_POST[ $field['id'] ] ) ? wc_clean( wp_unslash( $_POST[ $field['id'] ] ) ) : '';
				// Update a field if it includes an update callback.
				if ( isset( $field['update_callback'] ) ) {
					call_user_func( $field['update_callback'], $field['id'], $value, $order );
				} elseif ( is_callable( array( $order, 'set_shipping_' . $key ) ) ) {
					$props[ 'shipping_' . $key ] = $value;
				} else {
					$order->update_meta_data( $field['id'], $value );
				}
			}
		}
		if ( isset( $_POST['_transaction_id'] ) ) {
			$props['transaction_id'] = wc_clean( wp_unslash( $_POST['_transaction_id'] ) );
		}
		// Payment method handling.
		if ( $order->get_payment_method() !== wc_clean( wp_unslash( $_POST['_payment_method'] ) ) ) {
			$methods              = WC()->payment_gateways->payment_gateways();
			$payment_method       = wc_clean( wp_unslash( $_POST['_payment_method'] ) );
			$payment_method_title = $payment_method;
			if ( isset( $methods ) && isset( $methods[ $payment_method ] ) ) {
				$payment_method_title = $methods[ $payment_method ]->get_title();
			}
			if ( 'other' === $payment_method ) {
				$payment_method_title = esc_html__( 'Other', 'woocommerce' );
			}
			$props['payment_method']       = $payment_method;
			$props['payment_method_title'] = $payment_method_title;
		}
		// Update date.
		if ( empty( $_POST['order_date'] ) ) {
			$date = time();
		} else {
			if ( ! isset( $_POST['order_date_hour'] ) || ! isset( $_POST['order_date_minute'] ) || ! isset( $_POST['order_date_second'] ) ) {
				throw new Exception( __( 'Order date, hour, minute and/or second are missing.', 'woocommerce' ), 400 );
			}
			// phpcs:ignore WordPress.Security.ValidatedSanitizedInput
			$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'] ) );
		}
		$props['date_created'] = $date;
		// Set created via prop if new post.
		if ( isset( $_POST['original_post_status'] ) && 'auto-draft' === $_POST['original_post_status'] ) {
			$props['created_via'] = 'admin';
		}
		// Customer note.
		if ( isset( $_POST['customer_note'] ) ) {
			$props['customer_note'] = sanitize_textarea_field( wp_unslash( $_POST['customer_note'] ) );
		}
		// Save order data.
		$order->set_props( $props );
		$order->set_status( wc_clean( wp_unslash( $_POST['order_status'] ) ), '', true );
		$order->save();
		// phpcs:enable WordPress.Security.NonceVerification.Missing
	}
}