Last active
June 10, 2024 13:34
-
-
Save jeherve/a07ccf469025d722ad7016f6953146fd to your computer and use it in GitHub Desktop.
Remove state field from woocommerce checkout form.
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 | |
/** | |
* Remove state field from woocommerce checkout form. | |
* | |
* @see https://github.com/woocommerce/woocommerce/blob/3.1.2/includes/class-wc-countries.php#L629 | |
* | |
* @param array $fields Array of default address fields. | |
*/ | |
function jeherve_remove_state_field( $fields ) { | |
unset( $fields['state'] ); | |
return $fields; | |
} | |
add_filter( 'woocommerce_default_address_fields', 'jeherve_remove_state_field' ); |
That's not something you'll be able to achieve via this filter, since you'll need to change the value as the customer enters their contact info. I would recommend that you look for plugins and solutions that allow you to define dynamic checkout fields, such as https://woocommerce.com/products/conditional-checkout-fields-for-woocommerce/
Thank You so much jeherve
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And how to customize that if, for example I'd like to hide only for specific countries (eg. France and Germany) ?