Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

WooCommerce Update 'broke' checkout // Change locale setting(s) WordPress


Hi there,

I am having trouble with the most recent update to our WooCommerce store... Since 2.1.x we are running into an issue with our checkout page where the locale settings overwrite the changes made within our theme's functions.php – or at least it looks this way...

Essentially we had everything running smoothly before and now the process has somehow be remodelled and the "billing_state" field is automatically hidden (behaviour is based on country selection). I tried some code examples already and judging by the array's print it has changed alright but there must be something hooking in beforehand which renders the changes useless.

We make use of a customized verification process but this can't be the issue since it also occurs with the basic twenty fourteen theme...

<strong>Take a look at how things are with our live site over at:</strong> (put something in the cart first)

<strong>Now the difference after having updated to WooCommerce 2.1.x (user: evance, pass: lovelylena):</strong> (same here, need at least one item in cart, also: scroll down, page starts after array-print & ignore the post code validation error)

With the latter one you only see the billing_state-field when you have made your country-selction. This behaviour breaks our existing field ordering and the CSS so I'd rather not have this... Possible solutions:

<em>1) Disable the Country-Switcher by default, just leave one basic "state" field (not country-dependant)
2) Make the fields non-hidden for country codes DE, AT & CH
3) ???</em>

I don't want to use any extra plugin because we have already made our customizations and using one would only produce more trouble I am sure. Also it might not even change anything since the docs over at Woo state that the locale settings can't be changed with the plugin anyhow.

Here goes our functions.php (only the parts concerning the checkout):

//// Checkout Fields Modification (General)

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

function custom_override_checkout_fields( $fields ) {

$fields['billing']['billing_company']['label'] = (isset($_COOKIE['service_checked'])) ? 'Firmenname / Name der Einrichtung' : 'Firmenname (optional)';
$fields['billing']['billing_company']['clear'] = true;
$fields['billing']['billing_company']['required'] = (isset($_COOKIE['service_checked'])) ? true : false;
$fields['billing']['billing_address_1']['placeholder'] = false;
$fields['billing']['billing_address_2']['label'] = 'Stockwerk, Hinterhof, etc. (optional)';
$fields['billing']['billing_address_2']['placeholder'] = false;
$fields['billing']['billing_postcode']['placeholder'] = false;
$fields['billing']['billing_postcode']['clear'] = false;
$fields['billing']['billing_city']['placeholder'] = false;
$fields['billing']['billing_city']['clear'] = false;
$fields['billing']['billing_state']['label'] = 'Bundesland / Kanton / Bezirk (optional)';
$fields['billing']['billing_state']['placeholder'] = false;
$fields['billing']['billing_phone']['required'] = false;
$fields['billing']['billing_phone']['label'] = 'Telefonnummer (optional)';
$fields['billing']['billing_anrede'] = array(
'label' => __('Anrede', 'woocommerce'),
'placeholder' => _x('Anrede', 'placeholder', 'woocommerce'),
'required' => true,
'clear' => true,
'type' => 'select',
'class' => array('form-row form-row-first billing_anrede_dropdown'),
'options' => array(
'Frau' => __('Frau', 'woocommerce' ),
'Herr' => __('Herr', 'woocommerce' )

$fields['shipping']['shipping_company']['label'] = 'Firmenname (optional)';
$fields['shipping']['shipping_company']['clear'] = true;
$fields['shipping']['shipping_address_1']['placeholder'] = false;
$fields['shipping']['shipping_address_2']['label'] = 'Stockwerk, Hinterhof, etc. (optional)';
$fields['shipping']['shipping_address_2']['placeholder'] = false;
$fields['shipping']['shipping_postcode']['placeholder'] = false;
$fields['shipping']['shipping_city']['placeholder'] = false;
$fields['shipping']['shipping_state']['label'] = 'Bundesland / Kanton / Bezirk (optional)';
$fields['shipping']['shipping_state']['placeholder'] = false;
$fields['shipping']['shipping_anrede'] = array(
'label' => __('Anrede', 'woocommerce'),
'placeholder' => _x('Anrede', 'placeholder', 'woocommerce'),
'required' => true,
'clear' => true,
'type' => 'select',
'class' => array('form-row form-row-first shipping_anrede_dropdown'),
'options' => array(
'Frau' => __('Frau', 'woocommerce' ),
'Herr' => __('Herr', 'woocommerce' )

$fields['order']['order_comments']['label'] = 'Anmerkungen zu Ihrer Bestellung (optional)';
$fields['order']['order_comments']['placeholder'] = false;


return $fields;

//// Checkout Fields Ordering


function reorder_woo_fields($fields) {

$fields2['billing']['billing_anrede'] = $fields['billing']['billing_anrede'];
$fields2['billing']['billing_first_name'] = $fields['billing']['billing_first_name'];
$fields2['billing']['billing_last_name'] = $fields['billing']['billing_last_name'];
$fields2['billing']['billing_company'] = $fields['billing']['billing_company'];
$fields2['billing']['billing_address_1'] = $fields['billing']['billing_address_1'];
$fields2['billing']['billing_address_2'] = $fields['billing']['billing_address_2'];
$fields2['billing']['billing_postcode'] = $fields['billing']['billing_postcode'];
$fields2['billing']['billing_city'] = $fields['billing']['billing_city'];
$fields2['billing']['billing_state'] = $fields['billing']['billing_state'];
$fields2['billing']['billing_country'] = $fields['billing']['billing_country'];
$fields2['billing']['billing_email'] = $fields['billing']['billing_email'];
$fields2['billing']['billing_phone'] = $fields['billing']['billing_phone'];

$fields2['shipping']['shipping_anrede'] = $fields['shipping']['shipping_anrede'];
$fields2['shipping']['shipping_first_name'] = $fields['shipping']['shipping_first_name'];
$fields2['shipping']['shipping_last_name'] = $fields['shipping']['shipping_last_name'];
$fields2['shipping']['shipping_company'] = $fields['shipping']['shipping_company'];
$fields2['shipping']['shipping_address_1'] = $fields['shipping']['shipping_address_1'];
$fields2['shipping']['shipping_address_2'] = $fields['shipping']['shipping_address_2'];
$fields2['shipping']['shipping_postcode'] = $fields['shipping']['shipping_postcode'];
$fields2['shipping']['shipping_city'] = $fields['shipping']['shipping_city'];
$fields2['shipping']['shipping_state'] = $fields['shipping']['shipping_state'];
$fields2['shipping']['shipping_country'] = $fields['shipping']['shipping_country'];

//just copying these (keeps the standard order)
$fields2['account'] = $fields['account'];
$fields2['order'] = $fields['order'];

return $fields2;

//// Further Customization for "Anrede"

/** Update the order meta with field value **/
add_action('woocommerce_checkout_update_order_meta', 'anrede_update_order_meta');

function anrede_update_order_meta( $order_id ) {
if ($_POST['billing_anrede']) update_post_meta( $order_id, 'Anrede (Rechnungsadresse)', esc_attr($_POST['billing_anrede']));
if ($_POST['shipping_anrede']) update_post_meta( $order_id, 'Anrede (Lieferadresse)', esc_attr($_POST['shipping_anrede']));

/** Display field value on the order edition page (BILLING) **/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'billing_anrede_display_admin_order_meta', 10, 1 );

function billing_anrede_display_admin_order_meta($order){
echo '<p><strong>'.__('Anrede').':</strong> ' . $order->order_custom_fields['_billing_anrede'][0] . '</p>';

/** Display field value on the order edition page (SHIPPING) **/
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'shipping_anrede_display_admin_order_meta', 10, 1 );

function shipping_anrede_display_admin_order_meta($order){
echo '<p><strong>'.__('Anrede').':</strong> ' . $order->order_custom_fields['_shipping_anrede'][0] . '</p>';

This is the code in functions.php I tried to change/override the locale setting:

function custom_override_address_formats( $address_formats ) {

$address_formats['DE'] = '{name}\n{company}\n{address_1}\n{city}\n{state}\n{postcode}\n{country}';

return $address_formats;

add_filter( 'woocommerce_address_formats' , 'custom_override_address_formats' );

function custom_override_locale_setting ( $locale ) {

$locale['DE']['state']['hidden'] = false;
$locale['DE']['state']['label'] = 'Bundesland';
$locale['CH']['state']['label'] = false;

echo '<pre>';
echo '</pre>';

return $locale;


add_filter('woocommerce_get_country_locale', 'custom_override_locale_setting');

Input regarding the locale settings (2 years old but maybe useful):

<blockquote>on the checkout page i used the 'woocommerce_billing_fields' filter to remove or rearrange some fields and make others optional. but every field (ie zip code) that uses the woocommerce.js to update the price/shipping is ignoring the filter.</blockquote>

[[LINK href=""]][[/LINK]]

Looking forward to your proposals!
Thanks & regards,


Answers (1)


Arnav Joy answers:

are you sure your old woocommerce plugin is not customize ?
may be there is any change in the plugin files?

leanderb comments:

Hi Arnav,

I am 100% sure that no core files @ WooCommerce have been edited, all that has been done is stated above. The same behaviour is to be witnessed with the WooCommerce demo-store: – selecting "Germany" automatically omits the state-field which I don't want to happen.


leanderb comments:

<strong>I have found a solution to my problem</strong> and wanted to post it here for everyone else struggling with changes to their checkout pages:

I went ahead and introduced arrayed-lists of the available states for each country / locale which forces WooCommerce to display the state-field. The code for your functions.php should look like follows – do this for every country you have. Works only for checkout pages with few countries though I guess because I had to manually insert those :)

add_filter( 'woocommerce_states', 'custom_woocommerce_states' );

function custom_woocommerce_states( $states ) {

$states['AT'] = array(
'BGLD' => __('Burgenland', 'woocommerce') ,
'KTN' => __('Kärnten', 'woocommerce') ,
'NÖ' => __('Niederösterreich', 'woocommerce') ,
'OÖ' => __('Ober-Österreich', 'woocommerce') ,
'SGB' => __('Salzburg', 'woocommerce') ,
'STMK' => __('Steiermark', 'woocommerce') ,
'T' => __('Tirol', 'woocommerce') ,
'VBG' => __('Voralberg', 'woocommerce') ,
'W' => __('Wien', 'woocommerce')

return $states;