1. Home
  2. Snippets
  3. Create additional schemes for the Address field

Create additional schemes for the Address field

Heads up!

This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Dismiss

The Address field provides 2 different address schemes to choose from, US and International. Additional formats can be made available with a filter.

The snippets below demonstrate how you can create new schemes for other countries, such as Canada or Australia.

/**
 * WPForms Add new address field scheme (Canada)
 *
 * @param array $schemes
 * @return array
 */
function wpf_dev_new_address_scheme( $schemes ) {
	$schemes['canada'] = array(
		'label'          => 'Canada',
		'address1_label' => 'Address Line 1',
		'address2_label' => 'Address Line 2',
		'city_label'     => 'City',
		'postal_label'   => 'Code Postal',
		'state_label'    => 'Province',
		'states'         => array(
			'AB' => 'Alberta',
			'BC' => 'British Columbia',
			'MB' => 'Manitoba',
			'NB' => 'New Brunswick',
			'NL' => 'Newfoundland and Labrador',
			'NS' => 'Nova Scotia',
			'ON' => 'Ontario',
			'PE' => 'Prince Edward Island',
			'WQ' => 'Quebec',
			'SK' => 'Saskatchewan',
		),
	);
	return $schemes;
}
add_filter( 'wpforms_address_schemes', 'wpf_dev_new_address_scheme' );
/**
 * WPForms Add new address field scheme (Australia)
 *
 * @param array $schemes
 * @return array
 */
function wpf_dev_new_address_scheme( $schemes ) {
	$schemes['australia'] = array(
		'label'          => 'Australia',
		'address1_label' => 'Address Line 1',
		'address2_label' => 'Address Line 2',
		'city_label'     => 'City',
		'postal_label'   => 'Postal',
		'state_label'    => 'State / Territory',
		'states'         => array(
			'NSW' => 'New South Wales',
			'VIC' => 'Victoria',
			'QLD' => 'Queensland',
			'WA'  => 'Western Australia',
			'SA'  => 'South Australia',
			'TAS' => 'Tasmania',
			'ACT' => 'Australia Capital Territory',
			'NT'  => 'Northern Territory',
		),
	);
	return $schemes;
}
add_filter( 'wpforms_address_schemes', 'wpf_dev_new_address_scheme' );
Updated on November 20, 2017

Was this article helpful?