Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active March 22, 2020 06:38
Show Gist options
  • Save Shelob9/fa9db37404b9c0c727c7455854321316 to your computer and use it in GitHub Desktop.
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/
<?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;
});
<?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;
});
<?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;
});
@Nasirkhan-259
Copy link

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