jQuery( document ).ready( function( $ ) { let initialCountry = 'no'; $.get( "https://piyribbons.com/wp-admin/admin-ajax.php", { action: 'wpitfdc_get_visitor_country' }, function( data ) { initialCountry = data; do_the_plugin_thing(); } ); function do_the_plugin_thing() { $( "input[type='tel']" ).each( function( index, el ) { var name = ( typeof $( el ).attr( 'name' ) != 'undefined' && $( el ).attr( 'name' ) != '' ) ? $( el ).attr( 'name' ) : 'phoneNumber'; $( el ).removeAttr( 'name' ); var id = Date.now(); $( el ).after( '' ); $( el ).intlTelInput( { excludeCountries: [], initialCountry: initialCountry, onlyCountries: [], preferredCountries: [], separateDialCode: true, } ); setInterval( function() { var newVal = $( "input#countryCode" + id ).prev( '.iti' ).find( '.iti__selected-dial-code' ).text() + $( el ).val(); if ( newVal == $( "input#countryCode" + id ).val() ) { return; } if ( $( el ).val() == '' ) { newVal = ''; } $( "input#countryCode" + id ).val( newVal ); }, 1000 ); } ); } } );