Skip to content

Instantly share code, notes, and snippets.

@clifgriffin
Created June 23, 2022 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clifgriffin/63dd30c252df4211e02a9525b0ead9f0 to your computer and use it in GitHub Desktop.
Save clifgriffin/63dd30c252df4211e02a9525b0ead9f0 to your computer and use it in GitHub Desktop.
Handling extra long state field label with CheckoutWC and WooCommerce
<?php
/**
* Handling long state labels
*
* Example: German state field label exceeds state field container ("Bundesland / Landkreis (optional)")
*/
// Option 1: Rearrange address fields to make state field wider
add_filter(
'woocommerce_default_address_fields',
function( $fields ) {
$fields['country']['columns'] = 6;
$fields['state']['columns'] = 6;
$fields['postcode']['columns'] = 6;
$fields['city']['columns'] = 6;
return $fields;
},
100000 + 100
);
// Option 2: Require the state field
add_filter(
'woocommerce_get_country_locale',
function ( $locale ) {
$locale['DE']['state']['required'] = true;
return $locale;
},
10,
1
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment