Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFieldsAdmin::admin_address_fields()publicWC 1.0

Injects address fields in WC admin orders screen.

Method of the class: CheckoutFieldsAdmin{}

No Hooks.

Return

Array.

Usage

$CheckoutFieldsAdmin = new CheckoutFieldsAdmin();
$CheckoutFieldsAdmin->admin_address_fields( $fields, $order, $context );
$fields(array) (required)
The fields to show.
$order(\WC_Order|true|false)
The order to show the fields for.
Default: null
$context(string)
The context to show the fields for.
Default: 'edit'

CheckoutFieldsAdmin::admin_address_fields() code WC 9.0.1

public function admin_address_fields( $fields, $order = null, $context = 'edit' ) {
	if ( ! $order instanceof \WC_Order ) {
		return $fields;
	}

	$group_name        = doing_action( 'woocommerce_admin_billing_fields' ) ? 'billing' : 'shipping';
	$additional_fields = $this->checkout_fields_controller->get_order_additional_fields_with_values( $order, 'address', $group_name, $context );
	foreach ( $additional_fields as $key => $field ) {
		$prefixed_key              = CheckoutFields::get_group_key( $group_name ) . $key;
		$additional_fields[ $key ] = $this->format_field_for_meta_box( $field, $prefixed_key );
	}

	array_splice(
		$fields,
		array_search(
			'state',
			array_keys( $fields ),
			true
		) + 1,
		0,
		$additional_fields
	);

	return $fields;
}