Close

Caldera forms change default country in phone field to Spanish ES

3 / 100

Hi mates today I’m going to show you how to add some special filters to your Caldera Forms in order to set initial phone fields.
Surely there is some other better way to do this but since I didn’t find any other I just add some filters to the Caldera Forms options.

/**
* 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' ] = 'ES';
	return $options;
});
/**
* Set preferred 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;
});
/**
 * Show only specific countries' flag in Caldera Forms phone fields
 */
add_filter( 'caldera_forms_phone_js_options', function($options ){
	$options[ 'onlyCountries' ] = array( 'ES', 'es' );
	return $options;
});