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_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_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(); } /** * Whether an order has no persisted shipping method. * * A shipping line is order-time fulfillment evidence that remains stable when a * merchant later changes the ordered catalog products. Orders that retain one, * including Store API local pickup orders, must keep showing shipping details. * * @param WC_Order $order Order object. * @return bool */ private static function order_has_no_shipping( $order ) { return 0 === count( $order->get_shipping_methods() ); } /** * Whether every resolvable product line on an order is currently virtual. * * This check is used only when no persisted shipping method provides historical * fulfillment evidence. It intentionally reflects current, filterable catalog * semantics, so product edits can change the summary for no-line orders. Empty * or unresolved product sets remain visible because suppressing their persisted * shipping details would be ambiguous. * * Reading live catalog state is a deliberate, bounded departure from PR #66488's * principle that suppression should rest on order-time evidence immune to later * catalog edits. This fallback runs only for orders with no persisted shipping line * (guaranteed by order_has_no_shipping() earlier in the gate's && chain), which is * exactly the population that carries no such order-time evidence, so the catalog * read is the only available signal and can never override a persisted shipping line. * The accepted tradeoff: reclassifying a product as virtual can later re-hide a * no-line order that genuinely shipped. That recurrence is display-only, admin-only, * filterable, and pinned as intended by * test_hides_shipping_details_after_physical_product_without_shipping_line_becomes_virtual(). * * The aggregation and fallback here are deliberately local rather than reusing * WC_Order::needs_shipping() or the shipping-label helpers: needs_shipping() * short-circuits on the global shipping setting and, like those helpers, does not * default unresolved or product-less orders to the conservative "keep visible" * outcome this summary requires. * * @param WC_Order $order Order object. * @return bool */ private static function order_has_only_virtual_products( $order ) { $items = $order->get_items(); if ( empty( $items ) ) { return false; } foreach ( $items as $item ) { if ( ! $item instanceof WC_Order_Item_Product ) { return false; } $product = $item->get_product(); if ( ! $product instanceof WC_Product || $product->needs_shipping() ) { return false; } } return true; } /** * Whether an order's shipping address is still the billing-derived copy. * * Store API checkout copies the billing address into the shipping address for * backwards compatibility when a purchase needs no fulfillment. There is no persisted * marker for that copy, so the shipping address is treated as billing-derived only * while every copied field still matches billing. Once a merchant or integration edits * the shipping fields to diverge, the values are explicit and must be shown. * Individual getters use the edit context instead of get_address() so view filters * cannot make distinct persisted values appear equal. * * @param WC_Order $order Order object. * @return bool */ private static function order_shipping_matches_billing( $order ) { $copied_fields = array( 'first_name', 'last_name', 'company', 'address_1', 'address_2', 'city', 'state', 'postcode', 'country', 'phone' ); foreach ( $copied_fields as $field ) { if ( $order->{"get_shipping_$field"}( 'edit' ) !== $order->{"get_billing_$field"}( 'edit' ) ) { return false; } } return true; } /** * 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' ); ?>
get_date_created() ) ? $order->get_date_created()->getOffsetTimestamp() : ''; ?> :
get_user_id() ) { $user_id = absint( $order->get_user_id() ); $user = Users::get_user_in_current_site( $user_id ); if ( ! is_wp_error( $user ) ) { $customer = new WC_Customer( $user_id ); /* translators: 1: user display name 2: user ID 3: user email */ $found_users = array( $user_id => 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() ), ); } else { // print customer not available in the current site. $found_users = array( $user_id => esc_html__( '(Not available)', 'woocommerce' ) ); } } ?>
' . esc_html( $details_not_available_message ) . '
'; } else { if ( $order->get_formatted_billing_address() ) { echo '' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '
'; } else { echo '' . 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 ) { $normalized_email = is_string( $field_value ) ? trim( $field_value ) : ''; $field_value = '' === $normalized_email ? '' . esc_html__( 'No email address set.', 'woocommerce' ) . '' : '' . esc_html( $normalized_email ) . ''; } else { $field_value = make_clickable( esc_html( $field_value ) ); } if ( $field_value || '0' === $field_value ) { echo '' . esc_html( $field['label'] ) . ': ' . wp_kses_post( $field_value ) . '
'; } } } ?>'_transaction_id', 'label' => __( 'Transaction ID', 'woocommerce' ), 'value' => $order->get_transaction_id( 'edit' ), ), $order ); ?>
' . esc_html( $details_not_available_message ) . '
'; } else { $hide_core_shipping_details = 'store-api' === $order->get_created_via() && self::order_has_no_shipping( $order ) && self::order_has_only_virtual_products( $order ) && self::order_shipping_matches_billing( $order ); /** * Filters whether billing-derived shipping details are hidden in the order admin summary. * * @param bool $hide_core_shipping_details Whether core shipping details are hidden. * @param WC_Order $order Order object. * * @since 11.1.0 */ $hide_core_shipping_details = apply_filters( 'woocommerce_hide_order_admin_shipping_details', $hide_core_shipping_details, $order ); $shipping_address = $hide_core_shipping_details ? '' : $order->get_formatted_shipping_address(); if ( $shipping_address ) { echo '' . wp_kses( $shipping_address, array( 'br' => array() ) ) . '
'; } else { echo '' . 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 ( $hide_core_shipping_details && 'phone' === $key && ! isset( $field['value'] ) ) { continue; } 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 || '0' === $field_value ) { 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( wc_wptexturize_order_note( $order->get_customer_note() ) ) ), array( 'br' => array() ) ) . '
'; } } ?>