Você está visualizando atualmente WooCommerce: Additional “Store Address” @ General Settings

WooCommerce: Additional “Store Address” @ General Settings

  • Autor do post:
  • Categoria do post:Woocommerce
  • Tempo de leitura:4 minutos de leitura

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’, ” );

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?”

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 🙂

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!

Source