Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFieldsFrontend::edit_address_fields()publicWC 1.0

Adds additional address fields to the My Account edit address form.

Method of the class: CheckoutFieldsFrontend{}

No Hooks.

Return

Array. Updated address fields.

Usage

$CheckoutFieldsFrontend = new CheckoutFieldsFrontend();
$CheckoutFieldsFrontend->edit_address_fields( $address, $address_type );
$address(array) (required)
Address fields.
$address_type(string) (required)
Type of address (billing or shipping).

CheckoutFieldsFrontend::edit_address_fields() code WC 9.0.1

public function edit_address_fields( $address, $address_type ) {
	$customer = new WC_Customer( get_current_user_id() );
	$fields   = $this->checkout_fields_controller->get_fields_for_location( 'address' );

	foreach ( $fields as $key => $field ) {
		$field_key                      = CheckoutFields::get_group_key( $address_type ) . $key;
		$address[ $field_key ]          = $field;
		$address[ $field_key ]['value'] = $this->checkout_fields_controller->get_field_from_object( $key, $customer, $address_type );

		if ( 'select' === $field['type'] ) {
			$address[ $field_key ]['options'] = array_column( $field['options'], 'label', 'value' );
		}

		if ( 'checkbox' === $field['type'] ) {
			$address[ $field_key ]['checked_value']   = '1';
			$address[ $field_key ]['unchecked_value'] = '0';
		}
	}

	return $address;
}