Created
July 17, 2025 08:37
-
-
Save xlplugins/85e19199860c10bf27f62dabc739ad32 to your computer and use it in GitHub Desktop.
Funnelkit Checkout: Enable State Field force fullfuly
This file contains hidden or 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
add_filter( 'wfacp_form_section', function( $section ) { | |
$field_ids = wp_list_pluck( $section['fields'], 'id' ); | |
$field_pairs = [ | |
'billing_country' => 'billing_state', | |
'shipping_country' => 'shipping_state', | |
]; | |
foreach ( $field_pairs as $country_id => $state_id ) { | |
if ( in_array( $country_id, $field_ids ) && ! in_array( $state_id, $field_ids ) ) { | |
// Find country field data and its position | |
foreach ( $section['fields'] as $index => $field ) { | |
if ( $field['id'] === $country_id ) { | |
$country_class = isset( $field['class'] ) ? $field['class'] : []; | |
// Prepare new state field, copying class from country field | |
$state_field = [ | |
'id' => $state_id, | |
'name' => $state_id, | |
'type' => 'state', | |
'label' => 'State', | |
'required' => true, | |
'class' => $country_class, // Copy class | |
'priority' => 80, | |
]; | |
// Insert state field after country field | |
array_splice( $section['fields'], $index + 1, 0, [ $state_field ] ); | |
break; // No need to continue loop | |
} | |
} | |
} | |
} | |
return $section; | |
}, 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment