Last active
March 22, 2020 06:38
-
-
Save Shelob9/fa9db37404b9c0c727c7455854321316 to your computer and use it in GitHub Desktop.
Change Caldera Forms phone field default country. See: https://calderaforms.com/doc/caldera_forms_phone_js_options/
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
<?php | |
/** | |
* Set preffered countries for Caldera Forms phone fields | |
*/ | |
add_filter( 'caldera_forms_phone_js_options', function( $options){ | |
//Use ISO_3166-1_alpha-2 formatted country code | |
$options[ 'preferredCountries' ] = array( 'MX' ); | |
return $options; | |
}); |
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
<?php | |
/** | |
* Set intiial country for Caldera Forms phone fields | |
*/ | |
add_filter( 'caldera_forms_phone_js_options', function( $options){ | |
//Use ISO_3166-1_alpha-2 formatted country code | |
$options[ 'initialCountry' ] = 'CH'; | |
return $options; | |
}); |
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
<?php | |
/** | |
* Show only specific countries' flag in Caldera Forms phone fields | |
*/ | |
add_filter( 'caldera_forms_phone_js_options', function($options ){ | |
$options[ 'onlyCountries' ] = array( 'cn', 'tw' ); | |
return $options; | |
}); |
How do I do this in the wordpress astra theme? thank you
I have the same issue i am using astra theme for some reason when i put the above code it works for the first time but when i reload again , the default country is gone again ,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rendermanGL,
I am wondering if you have a readily available solution or something in the making for functionality whereas GeoIP data is pulled before the form loads and then the matching country flag is fetched based on the IP address.
Alternatively and equally cool way to handle this would be based on user input - Country field should be on the form before the phone number and once a user selects the country the form would update the country code/flag in the phone field accordingly?
Thanks