Wordpress - WooCommerce get physical store address

The physical address of the store (and many other settings) are stored in WP's options table (wp_options where "wp_" is the table prefix being used on the site).

The option names are:

  • woocommerce_store_address
  • woocommerce_store_address_2
  • woocommerce_store_city
  • woocommerce_store_postcode
  • woocommerce_default_country

The tricky thing is the woocommerce_default_country value. That stores the country AND state/province info depending on your selection in the "Country/State" dropdown selector in the settings. If it's just a country, it will be the country code, but if it's country "plus" something, it will be separated by a colon ":" (such as "US:IL").

So the following is a generic way of doing a US address. Other countries/provinces may vary slightly depending on (1) what's in the woocommerce_default_country value (which may be just a country alone) and (2) how you want to output the info.

// The main address pieces:
$store_address     = get_option( 'woocommerce_store_address' );
$store_address_2   = get_option( 'woocommerce_store_address_2' );
$store_city        = get_option( 'woocommerce_store_city' );
$store_postcode    = get_option( 'woocommerce_store_postcode' );

// The country/state
$store_raw_country = get_option( 'woocommerce_default_country' );

// Split the country/state
$split_country = explode( ":", $store_raw_country );

// Country and state separated:
$store_country = $split_country[0];
$store_state   = $split_country[1];

echo $store_address . "<br />";
echo ( $store_address_2 ) ? $store_address_2 . "<br />" : '';
echo $store_city . ', ' . $store_state . ' ' . $store_postcode . "<br />";
echo $store_country;

This certainly could be condensed quite a bit and made neater, but I was verbose in the code for clarity.

Also, depending on the store location, etc, you may or may not want to include the country/state info at all, or you may want to alter what it output based on the saved value. For example, in the case of US addresses, the country is "US", not "USA", and the state info is the abbreviated mail code (i.e. "IL" for Illinois). So the actual value and how you intend to use it will determine what you want to do with it for output. (Hope that makes sense.)


Instead of the get_option() method mentioned above, it's much better to use the built-in functions via the main instance of WooCommerce WC(), thereby accessing the methods of the WC_Countries class:

WC()->countries->get_base_address();
WC()->countries->get_base_address_2();
WC()->countries->get_base_city();
WC()->countries->get_base_postcode();
WC()->countries->get_base_state();
WC()->countries->get_base_country();

For one, the place where the information is stored could change, but the method to get it stays the same. And secondly, in case a plugin changes the value using filters. Looking at the source the latter gets obvious:

public function get_base_address() {
    $base_address = get_option( 'woocommerce_store_address', '' );
    return apply_filters( 'woocommerce_countries_base_address', $base_address );
}

Additional information:

  • What's the difference between WC() and $woocommerce
  • Classes in WooCommerce