*/ private static $hidden_shipping = array(); /** * Hooks. */ public static function init() { add_filter( 'woocommerce_admin_billing_fields', array( __CLASS__, 'billing' ), 20, 3 ); add_filter( 'woocommerce_admin_shipping_fields', array( __CLASS__, 'shipping' ), 20, 3 ); add_filter( 'woocommerce_hide_order_admin_shipping_details', array( __CLASS__, 'note_hidden_shipping' ), PHP_INT_MAX, 2 ); } /** * Billing fields shown on the order screen. * * @param mixed $fields Fields. * @param mixed $order Order. * @param string $context "view" or "edit". * @return mixed */ public static function billing( $fields, $order = false, $context = 'edit' ) { return self::phone( $fields, $order, $context, 'billing' ); } /** * Shipping fields shown on the order screen. * * @param mixed $fields Fields. * @param mixed $order Order. * @param string $context "view" or "edit". * @return mixed */ public static function shipping( $fields, $order = false, $context = 'edit' ) { if ( $order instanceof \WC_Order && ! empty( self::$hidden_shipping[ $order->get_id() ] ) ) { return $fields; } return self::phone( $fields, $order, $context, 'shipping' ); } /** * Remembers whether WooCommerce hides the shipping details of an order; the value is passed through. * * @param mixed $hide Whether the details are hidden. * @param mixed $order Order. * @return mixed */ public static function note_hidden_shipping( $hide, $order = null ) { if ( $order instanceof \WC_Order ) { self::$hidden_shipping[ $order->get_id() ] = (bool) $hide; } return $hide; } /** * Adds the readable number as the shown value of the phone field. * * @param mixed $fields Fields. * @param mixed $order Order. * @param string $context "view" or "edit". * @param string $group "billing" or "shipping". * @return mixed */ private static function phone( $fields, $order, $context, $group ) { if ( 'view' !== $context || ! $order instanceof \WC_Order || ! is_array( $fields ) || ! isset( $fields['phone'] ) || ! is_array( $fields['phone'] ) || isset( $fields['phone']['value'] ) ) { return $fields; } $getter = 'get_' . $group . '_phone'; if ( ! is_callable( array( $order, $getter ) ) ) { return $fields; } $saved = (string) $order->$getter( 'edit' ); $shown = '' === $saved ? '' : Phone::shown( $saved, 'admin_order' ); if ( '' !== $shown && $shown !== $saved ) { $fields['phone']['value'] = $shown; } return $fields; } }