WC_Meta_Box_Order_Data::output()public staticWC 1.0

Output the metabox.

Method of the class: WC_Meta_Box_Order_Data{}

Return

null. Nothing (null).

Usage

$result = WC_Meta_Box_Order_Data::output( $post );
$post(WP_Post|WC_Order) (required)
Post or order object.

WC_Meta_Box_Order_Data::output() code WC 9.3.1

<?php
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' );
	?>
	<style type="text/css">
		#post-body-content, #titlediv { display:none }
	</style>
	<div class="panel-wrap woocommerce">
		<input name="post_title" type="hidden" value="<?php echo esc_attr( empty( $order->get_title() ) ? __( 'Order', 'woocommerce' ) : $order->get_title() ); ?>" />
		<input name="post_status" type="hidden" value="<?php echo esc_attr( $order->get_status() ); ?>" />
		<div id="order_data" class="panel woocommerce-order-data">
			<h2 class="woocommerce-order-data__heading">
				<?php

				printf(
					/* translators: 1: order type 2: order number */
					esc_html__( '%1$s #%2$s details', 'woocommerce' ),
					esc_html( $order_type_object->labels->singular_name ),
					esc_html( $order->get_order_number() )
				);

				?>
			</h2>
			<p class="woocommerce-order-data__meta order_number">
				<?php

				$meta_list = array();

				if ( $payment_method && 'other' !== $payment_method ) {
					$payment_method_string = sprintf(
						/* translators: %s: payment method */
						__( 'Payment via %s', 'woocommerce' ),
						esc_html( isset( $payment_gateways[ $payment_method ] ) ? $payment_gateways[ $payment_method ]->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 .= ' (<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $transaction_id ) . '</a>)';
							}
						}

						$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' ),
						'<span class="woocommerce-Order-customerIP">' . esc_html( $ip_address ) . '</span>'
					);
				}

				echo wp_kses_post( implode( '. ', $meta_list ) );

				?>
			</p>
			<?php
				/**
				 * Hook allowing extenders to render custom content
				 * within the Order details box.
				 *
				 * This allows urgent notices or other important
				 * order-related info to be displayed upfront in
				 * the order page. Example: display a notice if
				 * the order is disputed.
				 *
				 * @param $order WC_Order The order object being displayed.
				 * @since 7.9.0
				 */
				do_action( 'woocommerce_admin_order_data_after_payment_info', $order );
			?>
			<div class="order_data_column_container">
				<div class="order_data_column">
					<h3><?php esc_html_e( 'General', 'woocommerce' ); ?></h3>

					<p class="form-field form-field-wide">
						<?php
						$order_date_created_localised = ! is_null( $order->get_date_created() ) ? $order->get_date_created()->getOffsetTimestamp() : '';
						?>
						<label for="order_date"><?php esc_html_e( 'Date created:', 'woocommerce' ); ?></label>
						<input type="text" class="date-picker" name="order_date" maxlength="10" value="<?php echo esc_attr( date_i18n( 'Y-m-d', $order_date_created_localised ) ); ?>" 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])' ) ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>" />@
						&lrm;
						<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', $order_date_created_localised ) ); ?>" pattern="([01]?[0-9]{1}|2[0-3]{1})" />:
						<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', $order_date_created_localised ) ); ?>" pattern="[0-5]{1}[0-9]{1}" />
						<input type="hidden" name="order_date_second" value="<?php echo esc_attr( date_i18n( 's', $order_date_created_localised ) ); ?>" />
					</p>

					<p class="form-field form-field-wide wc-order-status">
						<label for="order_status">
							<?php
							esc_html_e( 'Status:', 'woocommerce' );
							if ( $order->needs_payment() ) {
								printf(
									'<a href="%s">%s</a>',
									esc_url( $order->get_checkout_payment_url() ),
									esc_html__( 'Customer payment page &rarr;', 'woocommerce' )
								);
							}
							?>
						</label>
						<select id="order_status" name="order_status" class="wc-enhanced-select">
							<?php
							$statuses = wc_get_order_statuses();
							foreach ( $statuses as $status => $status_name ) {
								echo '<option value="' . esc_attr( $status ) . '" ' . selected( $status, 'wc-' . $order->get_status( 'edit' ), false ) . '>' . esc_html( $status_name ) . '</option>';
							}
							?>
						</select>
					</p>

					<p class="form-field form-field-wide wc-customer-user">
						<!--email_off--> <!-- Disable CloudFlare email obfuscation -->
						<label for="customer_user">
							<?php
							esc_html_e( 'Customer:', 'woocommerce' );
							if ( $order->get_user_id( 'edit' ) ) {
								$args = array(
									'post_status'    => 'all',
									'post_type'      => 'shop_order',
									'_customer_user' => $order->get_user_id( 'edit' ),
								);
								printf(
									'<a href="%s">%s</a>',
									esc_url( add_query_arg( $args, admin_url( 'edit.php' ) ) ),
									' ' . esc_html__( 'View other orders &rarr;', 'woocommerce' )
								);
								printf(
									'<a href="%s">%s</a>',
									esc_url( add_query_arg( 'user_id', $order->get_user_id( 'edit' ), admin_url( 'user-edit.php' ) ) ),
									' ' . esc_html__( 'Profile &rarr;', 'woocommerce' )
								);
							}
							?>
						</label>
						<?php
						$user_string = '';
						$user_id     = '';
						if ( $order->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 &ndash; %3$s)', 'woocommerce' ),
								$customer->get_first_name() . ' ' . $customer->get_last_name(),
								$customer->get_id(),
								$customer->get_email()
							);
						}
						?>
						<select class="wc-customer-search" id="customer_user" name="customer_user" data-placeholder="<?php esc_attr_e( 'Guest', 'woocommerce' ); ?>" data-allow_clear="true">
							<?php
							// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment
							/**
							 * Filter to customize the display of the currently selected customer for an order in the order edit page.
							 * This is the same filter used in the ajax call for customer search in the same metabox.
							 *
							 * @since 7.2.0 (this instance of the filter)
							 *
							 * @param array @user_info An array containing one item with the name and email of the user currently selected as the customer for the order.
							 */
							?>
							<option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo esc_html( htmlspecialchars( wp_kses_post( current( apply_filters( 'woocommerce_json_search_found_customers', array( $user_string ) ) ) ) ) ); ?></option>
							<?php // phpcs:enable WooCommerce.Commenting.CommentHooks.MissingHookComment ?>
						</select>
						<!--/email_off-->
					</p>
					<?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>
				</div>
				<div class="order_data_column">
					<h3>
						<?php esc_html_e( 'Billing', 'woocommerce' ); ?>
						<a href="#" class="edit_address"><?php esc_html_e( 'Edit', 'woocommerce' ); ?></a>
						<span>
							<a href="#" class="load_customer_billing" style="display:none;"><?php esc_html_e( 'Load billing address', 'woocommerce' ); ?></a>
						</span>
					</h3>
					<div class="address">
						<?php
						// Display values.
						if ( $order->get_formatted_billing_address() ) {
							echo '<p>' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '</p>';
						} else {
							echo '<p class="none_set"><strong>' . esc_html__( 'Address:', 'woocommerce' ) . '</strong> ' . esc_html__( 'No billing address set.', 'woocommerce' ) . '</p>';
						}

						$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 = '<a href="' . esc_url( 'mailto:' . $field_value ) . '">' . $field_value . '</a>';
							} else {
								$field_value = make_clickable( esc_html( $field_value ) );
							}

							if ( $field_value ) {
								echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
							}
						}
						?>
					</div>

					<div class="edit_address">
						<?php
						// Display form.
						$billing_fields = self::get_billing_fields( $order, 'edit' );

						foreach ( $billing_fields as $key => $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;
							}
						}
						?>
						<p class="form-field form-field-wide">
							<label><?php esc_html_e( 'Payment method:', 'woocommerce' ); ?></label>
							<select name="_payment_method" id="_payment_method" class="first">
								<option value=""><?php esc_html_e( 'N/A', 'woocommerce' ); ?></option>
								<?php
								$found_method = false;

								foreach ( $payment_gateways as $gateway ) {
									if ( 'yes' === $gateway->enabled ) {
										echo '<option value="' . esc_attr( $gateway->id ) . '" ' . selected( $payment_method, $gateway->id, false ) . '>' . esc_html( $gateway->get_title() ) . '</option>';
										if ( $payment_method === $gateway->id ) {
											$found_method = true;
										}
									}
								}

								if ( ! $found_method && ! empty( $payment_method ) ) {
									echo '<option value="' . esc_attr( $payment_method ) . '" selected="selected">' . esc_html__( 'Other', 'woocommerce' ) . '</option>';
								} else {
									echo '<option value="other">' . esc_html__( 'Other', 'woocommerce' ) . '</option>';
								}
								?>
							</select>
						</p>
						<?php

						woocommerce_wp_text_input(
							array(
								'id'    => '_transaction_id',
								'label' => __( 'Transaction ID', 'woocommerce' ),
								'value' => $order->get_transaction_id( 'edit' ),
							),
							$order
						);
						?>

					</div>
					<?php do_action( 'woocommerce_admin_order_data_after_billing_address', $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>
				</div>
				<div class="order_data_column">
					<h3>
						<?php esc_html_e( 'Shipping', 'woocommerce' ); ?>
						<a href="#" class="edit_address"><?php esc_html_e( 'Edit', 'woocommerce' ); ?></a>
						<span>
							<a href="#" class="load_customer_shipping" style="display:none;"><?php esc_html_e( 'Load shipping address', 'woocommerce' ); ?></a>
							<a href="#" class="billing-same-as-shipping" style="display:none;"><?php esc_html_e( 'Copy billing address', 'woocommerce' ); ?></a>
						</span>
					</h3>
					<div class="address">
						<?php
						// Display values.
						if ( $order->get_formatted_shipping_address() ) {
							echo '<p>' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '</p>';
						} else {
							echo '<p class="none_set"><strong>' . esc_html__( 'Address:', 'woocommerce' ) . '</strong> ' . esc_html__( 'No shipping address set.', 'woocommerce' ) . '</p>';
						}

						$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 '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
							}
						}

						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 '<p class="order_note"><strong>' . esc_html( __( 'Customer provided note:', 'woocommerce' ) ) . '</strong> ' . wp_kses( nl2br( esc_html( $order->get_customer_note() ) ), array() ) . '</p>';
						}
						?>
					</div>
					<div class="edit_address">
						<?php
						// Display form.
						$shipping_fields = self::get_shipping_fields( $order, 'edit' );

						if ( ! empty( $shipping_fields ) ) {
							foreach ( $shipping_fields as $key => $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' ) ) ) :
							?>
							<p class="form-field form-field-wide">
								<label for="customer_note"><?php esc_html_e( 'Customer provided note', 'woocommerce' ); ?>:</label>
								<textarea rows="1" cols="40" name="customer_note" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer notes about the order', 'woocommerce' ); ?>"><?php echo wp_kses( $order->get_customer_note(), array() ); ?></textarea>
							</p>
						<?php endif; ?>
					</div>

					<?php do_action( 'woocommerce_admin_order_data_after_shipping_address', $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>
				</div>
			</div>
			<div class="clear"></div>
		</div>
	</div>
	<?php
}