How to Create Additional Schemes for the Address Field

Overview

Would you like to create additional address field layouts? WPForms offers the US and International but you can easily create more. This tutorial will show you how to use PHP to add additional address field layouts.

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

Setup

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

Simply choose and customize which code snippet you’d like to add to your site.

Canada

/**
 * WPForms Add new address field scheme (Canada)
 *
 * @link   https://wpforms.com/developers/create-additional-schemes-for-the-address-field/
 *
 * @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' );

Australia

/**
 * WPForms Add new address field scheme (Australia)
 *
 * @link   https://wpforms.com/developers/create-additional-schemes-for-the-address-field/
 *
 * @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' );

With either (or both) of the snippets above, you’ve now added new additional address schemes. Would you like to learn how to sublabels on the address field? Try out our article on How to Change the Address Field Sublabels.