How to pass value to add_filter wpcf7_form_tag from another function?

I haven’t tested this but you could try and use CF7’s wpcf7_form_hidden_fields and add this to the end of your ipgeolocation() function – then leave the form tag function as is but replace the hardcoded value with $country.

  // Update Contact Form 7 hidden field
        add_filter( 'wpcf7_form_hidden_fields', function( $hidden_fields ) use ( $country ) {
            $hidden_fields['user_country'] = $country;
            return $hidden_fields;
        } );