WooCommerce: Additional “Store Address” @ General Settings

So, we all know that the “Store Address” fields under WooCommerce > Settings > General are used by other WooCommerce functions such as the initial setup wizard, currency switchers, language plugins as well as taxes and shipping calculations. Also, it may display on PDF invoices, WooCommerce emails and static pages.

This is all good and easy, but as usual businesses are not made equal. It could be that you need to show an additional address; for example, the “Warehouse Address”.

In this tutorial, we will add a new “Warehouse Address” section and address fields under the “Store Address” settings, and also see how we can easily retrieve this custom address so that you can display it anywhere. Enjoy!

Here’s a brand new section called “Warehouse Address” that can be used for a second store address whenever it’s needed. The snippet below shows how to add these new settings, and further down you also find a way to retrieve the custom information.

PHP Snippet: Second Store Address @ WooCommerce > Settings > General

/**
 * @snippet       Second Address @ WooCommerce Settings
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'woocommerce_general_settings', 'bbloomer_additional_store_addresses_admin', 9999 );

function bbloomer_additional_store_addresses_admin( $settings ) {
	
	$new_settings = array(
	
		array(
			'title' => 'Warehouse Address',
			'type'  => 'title',
			'id'    => 'wh_address',
		),

		array(
			'title'    => __( 'Address line 1', 'woocommerce' ),
			'id'       => 'woocommerce_wh_address',
			'type'     => 'text',
		),

		array(
			'title'    => __( 'Address line 2', 'woocommerce' ),
			'id'       => 'woocommerce_wh_address_2',
			'type'     => 'text',
		),

		array(
			'title'    => __( 'City', 'woocommerce' ),
			'id'       => 'woocommerce_wh_city',
			'type'     => 'text',
		),

		array(
			'title'    => __( 'Country / State', 'woocommerce' ),
			'id'       => 'woocommerce_wh_country',
			'type'     => 'single_select_country',
		),

		array(
			'title'    => __( 'Postcode / ZIP', 'woocommerce' ),
			'id'       => 'woocommerce_wh_postcode',
			'type'     => 'text',
		),

		array(
			'type' => 'sectionend',
			'id'   => 'wh_address',
		),

   );
	
	return array_merge( array_slice( $settings, 0, 7 ), $new_settings, array_slice( $settings, 7 ) );
	
}

You’re wondering how I came up with the code above? Well, I simply found out how the General Settings are output by WooCommerce, found the handy woocommerce_general_settings filter, and copied the whole “Store Address” section after changing the fields’ ID.

Finally, I used a combination of array_slice and array_merge to position the new section exactly after the Store Address one.

The great thing is that no code is needed to “save” these new fields, WooCommerce does it already for you. Which means you can retrieve the new address in this way:

$warehouse_address = get_option( 'woocommerce_wh_address', '' );
$warehouse_address_2 = get_option( 'woocommerce_wh_address_2', '' );
$warehouse_city = get_option( 'woocommerce_wh_city', '' );
$warehouse_country = get_option( 'woocommerce_wh_country', '' );
$warehouse_zip = get_option( 'woocommerce_wh_postcode', '' );

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published. Required fields are marked *