mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/71037347/remove-specific-states-on-woocommerce-checkout-but-only-in-the-shipping-form/
17 lines
710 B
Text
17 lines
710 B
Text
function filter_woocommerce_form_field_state( $field, $key, $args, $value ) {
|
|
// Checkout page only
|
|
if ( ! is_checkout() ) return $field;
|
|
|
|
// Only for shipping
|
|
if ( $key == 'shipping_state' ) {
|
|
// Replace all occurrences of the search string with the replacement string
|
|
$field = str_replace( '<option value="CE" >Ceuta</option>', '', $field );
|
|
$field = str_replace( '<option value="ML" >Melilla</option>', '', $field );
|
|
$field = str_replace( '<option value="PM" >Baleares</option>', '', $field );
|
|
// Etc..
|
|
}
|
|
|
|
// Do something
|
|
return $field;
|
|
}
|
|
add_filter( 'woocommerce_form_field_state', 'filter_woocommerce_form_field_state', 10, 4 );
|