Hi @marashmallow
Hope you are doing fine!
Our Second Level Support team has provided a custom code that can help assign the default country setting of the phone field.
You’ll need to add a must-use plugin to your site’s wp-content/mu-plugins folder as explained in our documentation here: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins, then add the following code provided to the plugin’s php file:
<?php
add_filter(
'forminator_field_phone_markup',
function( $html, $id, $required, $placeholder, $value ) {
if ( ! empty( $_SERVER["HTTP_CF_IPCOUNTRY"] ) ) {
$formi_country_codes = array_keys( forminator_get_countries_list() );
if ( in_array( strtoupper( $_SERVER["HTTP_CF_IPCOUNTRY"] ), $formi_country_codes ) ) {
$html = preg_replace( '/(data-country=".*?")/s' , 'data-country="' . strtolower( esc_attr( $_SERVER["HTTP_CF_IPCOUNTRY"] ) ) . '"', $html );
}
}
return $html;
},
10,
5
);
Keep in mind though, the validation of the country code might not be 100% accurate. Forminator uses JavaScript libraries to map the country code which may not match with the ones provided by Cloudflare.
We recommend to test this on the dev/staging version first before putting it on the live site.
Hope this information helps.
Kind regards
Luis