By default Gravity Forms has three address type formats:
- International
- United States
- Canadian
International is the default address type and provides the most flexibility for the various address formats used worldwide.
You can however use a handful of hooks to customise these options and even create your own address type format.
In this example I’ll be creating the Australian address type format, using standards set by the postal authority – Australia Post.
These are:
- ‘Address line #’
- ‘Town/suburb’
- ‘State’
- ‘Postcode’ (one word)
This code will also add the Australian states as drop down options for the ‘State’ field, in alphabetical order.
And finally, it will set the new ‘Australian’ address type format to the default format when creating a new address field. (Note: you will need at least version 2.0.3.3 for this)
To use the code simply copy into your theme’s functions.php file – directly below the opening line – <?php
If you’re not sure how to do this you can download and install this plugin, which provides the exact same code as an installable plugin.
Download plugin: Gravity Forms – Australian address type
add_filter( 'gform_address_types', 'itsg_australian_address', 10, 2 ); function itsg_australian_address( $address_types, $form_id ){ $address_types['australian'] = array( 'label' => 'Australian', 'country' => 'Australia', 'state_label' => 'State', 'zip_label' => 'Postcode', 'states' => array( '', 'Australian Capital Territory', 'New South Wales', 'Northern Territory', 'Queensland', 'South Australia', 'Tasmania', 'Victoria', 'Western Australia' ) ); return $address_types; } add_filter( 'gform_address_street', 'itsg_change_address_street', 10, 2 ); function itsg_change_address_street( $label, $form_id ) { return 'Address line 1'; } add_filter( 'gform_address_street2', 'itsg_change_address_street3', 10, 2 ); function itsg_change_address_street3( $label, $form_id ) { return 'Address line 2'; } add_filter( 'gform_address_city', 'itsg_change_address_city', 10, 2 ); function itsg_change_address_city( $label, $form_id ) { return 'Town/suburb'; } add_filter( 'gform_address_state', 'itsg_change_address_state', 10, 2 ); function itsg_change_address_state( $label, $form_id ) { return 'State'; } add_filter( 'gform_address_zip', 'itsg_change_address_zip', 10, 2 ); function itsg_change_address_zip( $label, $form_id ) { return 'Postcode'; } add_filter( 'gform_default_address_type', 'itsg_set_default_country', 10, 2 ); function itsg_set_default_country( $default_address_type, $form_id ) { return 'australian'; }