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
 * @community     https://businessbloomer.com/club/
 */

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 custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Add Second Description @ Product Category Pages
    In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product category “description” and “thumbnail”. Most themes, if compatible with WooCommerce, will show this content right below the product category name and above products. Nothing new so far. But what if […]
  • WooCommerce: Add Column to Orders Table @ WP Dashboard
    The WooCommerce Orders Table, which can be found under WP Dashboard > WooCommerce > Orders, provides us with 7 default columns: Order – Date – Status – Billing – Ship to – Total – Actions. This is used by shop managers to have an overview of all orders, before eventually clicking on a specific one. […]
  • WooCommerce: Display Custom Filters @ WP Dashboard > Products
    If you go to WordPress Dashboard > Products you will find default product admin filters such as “Select a category”, “Filter by product type”, “Filter by stock status”. What if you want to add more custom filters to let your shop managers find products easily? For example, you could add “Filter by product tag” (“product […]
  • WooCommerce: Hide/Show The WP Admin Bar
    In previous WooCommerce versions, new customers could access the WP Admin black bar after purchase. Now this seems fixed. Still, what about other user roles, and what if you want to override this default behavior? Well, here’s a quick snippet for you – feel free to use it in your own WooCommerce site. Enjoy!
  • WooCommerce: Calculate Sales by State
    You’re filing your tax returns and need to know how much you earned in each state… but then find out WooCommerce doesn’t give you this calculation by default within its reports! Don’t worry – today I’ll share a quick snippet so that you can calculate the amount you need in a second. Feel free to […]

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. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. 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 the Business Bloomer Club to get quick WooCommerce support. Thank you!

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