Description
The gform_default_address_type filter can be used to override the default address type for new fields. It can be used together with the gform_address_types filter to add support for new country specific address types.
Usage
The base filter which would run for all forms would be used like so:
add_filter( 'gform_default_address_type', 'your_function_name', 10, 2 );
To target a specific form append the form id to the hook name. (format: gform_default_address_type_FORMID)
add_filter( 'gform_default_address_type_5', 'your_function_name', 10, 2 );
Parameters
| Parameter | Type | Description |
|---|---|---|
$default_address_type | string | The default address type, international. |
$form_id | integer | The current form ID |
Examples
Set the default address type to Australia.
This example shows how the default address type can be set to Australia. The Australian address type would need to have been added by the gform_address_types filter.
add_filter( 'gform_default_address_type', function ( $default_address_type, $form_id ) {
return 'australia';
}, 10, 2 );
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Since
This filter was added in Gravity Forms 2.0.3.2.
Source Code
This filter is located in GF_Field_Address::get_default_address_type() in includes/fields/class-gf-field-address.php.