Using Gravity Forms ‘gform_address_types’ PHP action

The gform_address_types Gravity Forms PHP filter is executed when creating the address field (admin and front end). It can be used to add support for a new address type.

Usage

A generic example of how to use the filter:

add_filter('gform_address_types', 'custom_address_type', 10, 2);

function custom_address_type($address_types, $form_id) {
    // your custom code here
    return $address_types;
}

Parameters

  • $address_types (array) – A list of all configured address types to be filtered.
  • $form_id (integer) – The current form ID.

More information

See Gravity Forms Docs: gform_address_types

Examples

Brazilian Address Type

Add a Brazilian address type to the list:

add_filter('gform_address_types', 'brazilian_address', 10, 2);

function brazilian_address($address_types, $form_id) {
    $address_types['brazil'] = array(
        'label' => 'Brasil',
        'country' => 'Brasil',
        'zip_label' => 'CEP',
        'state_label' => 'Estado',
        'states' => array(
            '', 'Acre', 'Alagoas', 'Amapa', 'Amazonas', 'Bahia', 'Ceara', 'Distrito Federal', 'Espirito Santo', 'Goias', 'Maranhao', 'Mato Grosso', 'Mato Grosso do Sul', 'Minas Gerais',
            'Para', 'Paraiba', 'Parana', 'Pernambuco', 'Piaui', 'Roraima', 'Rondonia', 'Rio de Janeiro', 'Rio Grande do Norte', 'Rio Grande do Sul', 'Santa Catarina', 'Sao Paulo', 'Sergipe', 'Tocantins'
        )
    );

    return $address_types;
}

Australian Address Type

Add an Australian address type:

add_filter('gform_address_types', 'australian_address_type');

function australian_address_type($address_types) {
    $address_types['australia'] = array(
        'label' => 'Australian',
        'country' => 'Australia',
        'zip_label' => 'Postcode',
        'state_label' => 'State',
        'states' => array(
            'ACT' => 'Australian Capital Territory',
            'NT' => 'Northern Territory',
            'NSW' => 'New South Wales',
            'QLD' => 'Queensland',
            'SA' => 'South Australia',
            'TAS' => 'Tasmania',
            'VIC' => 'Victoria',
            'WA' => 'Western Australia',
        )
    );

    return $address_types;
}