Created
June 23, 2022 13:24
-
-
Save clifgriffin/63dd30c252df4211e02a9525b0ead9f0 to your computer and use it in GitHub Desktop.
Handling extra long state field label with CheckoutWC and WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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