Alphabetical order countries
-
Hi Miyoshi-san,
Great plugin, in combination with your Contact Form 7.
Two questions:
1) When I select data:countries.un, some countries do not appear in alphabetical order, such as Switzerland, and United Kingdom. I suspect this has to do with the alphabetical order of the abbreviations (CH, GB), but it’s confusing. Would it be possible to resort the list alphabetically?
2) I would like to place a few common countries first, so people do not have to scroll down the whole list. E.g. I could start dropdown with empty value as is (“—“), then list a few selected ones (e.g. United Kingdom, USA, Canada), and then another separator (“—“) and then the full countries.un list. That would add a lot of convenience for my visitors…
Thanks a lot and congratulations again for the excellent work,
Kind Regards,
Siro
-
You can do it by adding your own function to the
wpcf7_form_tag_data_option
filter hook.See contact-form-7/modules/listo.php file as a reference.
OK, sorry, don’t know how to program.
But thanks for pointing me in the right direction. Found a workaround by editing manually the countries.php file in /listo/modules.
If helpful for other people, I resorted manually in excel and updated countries.php to contain the following: ct1 to ct9 include your custom countries, included them in the .un array, and the rest are sorted alphabetically by country name, instead of country 3 letter code.
<?php /** * The list of countries and dependent territories based on ISO 3166 standard. * * Source: https://en.wikipedia.org/wiki/ISO_3166-1 ISO 3166-1 */ class Listo_Countries implements Listo { private static $items = array( 'ct1' => "United Kingdom", 'ct2' => "United States", 'ct3' => "China", 'ct4' => "Turkey", 'ct5' => "India", 'ct6' => "Brazil", 'ct9' => " ——————— ", 'afg' => "Afghanistan", 'ala' => "?land Islands", 'alb' => "Albania", 'dza' => "Algeria", 'asm' => "American Samoa", 'and' => "Andorra", 'ago' => "Angola", 'aia' => "Anguilla", 'ata' => "Antarctica", 'atg' => "Antigua and Barbuda", 'arg' => "Argentina", 'arm' => "Armenia", 'abw' => "Aruba", 'aus' => "Australia", 'aut' => "Austria", 'aze' => "Azerbaijan", 'bhs' => "Bahamas", 'bhr' => "Bahrain", 'bgd' => "Bangladesh", 'brb' => "Barbados", 'blr' => "Belarus", 'bel' => "Belgium", 'blz' => "Belize", 'ben' => "Benin", 'bmu' => "Bermuda", 'btn' => "Bhutan", 'bol' => "Bolivia, Plurinational State of", 'bes' => "Bonaire, Sint Eustatius and Saba", 'bih' => "Bosnia and Herzegovina", 'bwa' => "Botswana", 'bvt' => "Bouvet Island", 'bra' => "Brazil", 'iot' => "British Indian Ocean Territory", 'brn' => "Brunei Darussalam", 'bgr' => "Bulgaria", 'bfa' => "Burkina Faso", 'bdi' => "Burundi", 'khm' => "Cambodia", 'cmr' => "Cameroon", 'can' => "Canada", 'cpv' => "Cape Verde", 'cym' => "Cayman Islands", 'caf' => "Central African Republic", 'tcd' => "Chad", 'chl' => "Chile", 'chn' => "China", 'cxr' => "Christmas Island", 'cck' => "Cocos (Keeling) Islands", 'col' => "Colombia", 'com' => "Comoros", 'cod' => "Congo, the Democratic Republic of the", 'cog' => "Congo", 'cok' => "Cook Islands", 'cri' => "Costa Rica", 'civ' => "C?te d'Ivoire", 'hrv' => "Croatia", 'cub' => "Cuba", 'cuw' => "Cura?ao", 'cyp' => "Cyprus", 'cze' => "Czech Republic", 'dnk' => "Denmark", 'dji' => "Djibouti", 'dma' => "Dominica", 'dom' => "Dominican Republic", 'ecu' => "Ecuador", 'egy' => "Egypt", 'slv' => "El Salvador", 'gnq' => "Equatorial Guinea", 'eri' => "Eritrea", 'est' => "Estonia", 'eth' => "Ethiopia", 'flk' => "Falkland Islands (Malvinas)", 'fro' => "Faroe Islands", 'fji' => "Fiji", 'fin' => "Finland", 'fra' => "France", 'guf' => "French Guiana", 'pyf' => "French Polynesia", 'atf' => "French Southern Territories", 'gab' => "Gabon", 'gmb' => "Gambia", 'geo' => "Georgia", 'deu' => "Germany", 'gha' => "Ghana", 'gib' => "Gibraltar", 'grc' => "Greece", 'grl' => "Greenland", 'grd' => "Grenada", 'glp' => "Guadeloupe", 'gum' => "Guam", 'gtm' => "Guatemala", 'ggy' => "Guernsey", 'gnb' => "Guinea-Bissau", 'gin' => "Guinea", 'guy' => "Guyana", 'hti' => "Haiti", 'hmd' => "Heard Island and McDonald Islands", 'vat' => "Holy See (Vatican City State)", 'hnd' => "Honduras", 'hkg' => "Hong Kong", 'hun' => "Hungary", 'isl' => "Iceland", 'ind' => "India", 'idn' => "Indonesia", 'irn' => "Iran, Islamic Republic of", 'irq' => "Iraq", 'irl' => "Ireland", 'imn' => "Isle of Man", 'isr' => "Israel", 'ita' => "Italy", 'jam' => "Jamaica", 'jpn' => "Japan", 'jey' => "Jersey", 'jor' => "Jordan", 'kaz' => "Kazakhstan", 'ken' => "Kenya", 'kir' => "Kiribati", 'prk' => "Korea, Democratic People's Republic of", 'kor' => "Korea, Republic of", 'kwt' => "Kuwait", 'kgz' => "Kyrgyzstan", 'lao' => "Lao People's Democratic Republic", 'lva' => "Latvia", 'lbn' => "Lebanon", 'lso' => "Lesotho", 'lbr' => "Liberia", 'lby' => "Libya", 'lie' => "Liechtenstein", 'ltu' => "Lithuania", 'lux' => "Luxembourg", 'mac' => "Macao", 'mkd' => "Macedonia, the former Yugoslav Republic of", 'mdg' => "Madagascar", 'mwi' => "Malawi", 'mys' => "Malaysia", 'mdv' => "Maldives", 'mli' => "Mali", 'mlt' => "Malta", 'mhl' => "Marshall Islands", 'mtq' => "Martinique", 'mrt' => "Mauritania", 'mus' => "Mauritius", 'myt' => "Mayotte", 'mex' => "Mexico", 'fsm' => "Micronesia, Federated States of", 'mda' => "Moldova, Republic of", 'mco' => "Monaco", 'mng' => "Mongolia", 'mne' => "Montenegro", 'msr' => "Montserrat", 'mar' => "Morocco", 'moz' => "Mozambique", 'mmr' => "Myanmar", 'nam' => "Namibia", 'nru' => "Nauru", 'npl' => "Nepal", 'nld' => "Netherlands", 'ncl' => "New Caledonia", 'nzl' => "New Zealand", 'nic' => "Nicaragua", 'ner' => "Niger", 'nga' => "Nigeria", 'niu' => "Niue", 'nfk' => "Norfolk Island", 'mnp' => "Northern Mariana Islands", 'nor' => "Norway", 'omn' => "Oman", 'pak' => "Pakistan", 'plw' => "Palau", 'pse' => "Palestine, State of", 'pan' => "Panama", 'png' => "Papua New Guinea", 'pry' => "Paraguay", 'per' => "Peru", 'phl' => "Philippines", 'pcn' => "Pitcairn", 'pol' => "Poland", 'prt' => "Portugal", 'pri' => "Puerto Rico", 'qat' => "Qatar", 'reu' => "Réunion", 'rou' => "Romania", 'rus' => "Russian Federation", 'rwa' => "Rwanda", 'blm' => "Saint Barthélemy", 'shn' => "Saint Helena, Ascension and Tristan da Cunha", 'kna' => "Saint Kitts and Nevis", 'lca' => "Saint Lucia", 'maf' => "Saint Martin (French part)", 'spm' => "Saint Pierre and Miquelon", 'vct' => "Saint Vincent and the Grenadines", 'wsm' => "Samoa", 'smr' => "San Marino", 'stp' => "Sao Tome and Principe", 'sau' => "Saudi Arabia", 'sen' => "Senegal", 'srb' => "Serbia", 'syc' => "Seychelles", 'sle' => "Sierra Leone", 'sgp' => "Singapore", 'sxm' => "Sint Maarten (Dutch part)", 'svk' => "Slovakia", 'svn' => "Slovenia", 'slb' => "Solomon Islands", 'som' => "Somalia", 'zaf' => "South Africa", 'sgs' => "South Georgia and the South Sandwich Islands", 'ssd' => "South Sudan", 'esp' => "Spain", 'lka' => "Sri Lanka", 'sdn' => "Sudan", 'sur' => "Suriname", 'sjm' => "Svalbard and Jan Mayen", 'swz' => "Swaziland", 'swe' => "Sweden", 'che' => "Switzerland", 'syr' => "Syrian Arab Republic", 'twn' => "Taiwan, Province of China", 'tjk' => "Tajikistan", 'tza' => "Tanzania, United Republic of", 'tha' => "Thailand", 'tls' => "Timor-Leste", 'tgo' => "Togo", 'tkl' => "Tokelau", 'ton' => "Tonga", 'tto' => "Trinidad and Tobago", 'tun' => "Tunisia", 'tur' => "Turkey", 'tkm' => "Turkmenistan", 'tca' => "Turks and Caicos Islands", 'tuv' => "Tuvalu", 'uga' => "Uganda", 'ukr' => "Ukraine", 'are' => "United Arab Emirates", 'gbr' => "United Kingdom", 'umi' => "United States Minor Outlying Islands", 'usa' => "United States", 'ury' => "Uruguay", 'uzb' => "Uzbekistan", 'vut' => "Vanuatu", 'ven' => "Venezuela, Bolivarian Republic of", 'vnm' => "Viet Nam", 'vgb' => "Virgin Islands, British", 'vir' => "Virgin Islands, U.S.", 'wlf' => "Wallis and Futuna", 'esh' => "Western Sahara", 'yem' => "Yemen", 'zmb' => "Zambia", 'zwe' => "Zimbabwe"); private static $groups = array( 'un' => array( 'ct1', 'ct2', 'ct3', 'ct4', 'ct5', 'ct6', 'ct7', 'ct8', 'ct9', 'ago', 'afg', 'alb', 'and', 'are', 'arg', 'arm', 'atg', 'aus', 'aut', 'aze', 'bdi', 'bel', 'ben', 'bfa', 'bgd', 'bgr', 'bhr', 'bhs', 'bih', 'blr', 'blz', 'bol', 'bra', 'brb', 'brn', 'btn', 'bwa', 'caf', 'can', 'che', 'chl', 'chn', 'civ', 'cmr', 'cod', 'cog', 'col', 'com', 'cpv', 'cri', 'cub', 'cyp', 'cze', 'deu', 'dji', 'dma', 'dnk', 'dom', 'dza', 'ecu', 'egy', 'eri', 'esp', 'est', 'eth', 'fin', 'fji', 'fra', 'fsm', 'gab', 'gbr', 'geo', 'gha', 'gin', 'gmb', 'gnb', 'gnq', 'grc', 'grd', 'gtm', 'guy', 'hnd', 'hrv', 'hti', 'hun', 'idn', 'ind', 'irl', 'irn', 'irq', 'isl', 'isr', 'ita', 'jam', 'jor', 'jpn', 'kaz', 'ken', 'kgz', 'khm', 'kir', 'kna', 'kor', 'kwt', 'lao', 'lbn', 'lbr', 'lby', 'lca', 'lie', 'lka', 'lso', 'ltu', 'lux', 'lva', 'mar', 'mco', 'mda', 'mdg', 'mdv', 'mex', 'mhl', 'mkd', 'mli', 'mlt', 'mmr', 'mne', 'mng', 'moz', 'mrt', 'mus', 'mwi', 'mys', 'nam', 'ner', 'nga', 'nic', 'nld', 'nor', 'npl', 'nru', 'nzl', 'omn', 'pak', 'pan', 'per', 'phl', 'plw', 'png', 'pol', 'prk', 'prt', 'pry', 'qat', 'rou', 'rus', 'rwa', 'sau', 'sdn', 'sen', 'sgp', 'slb', 'sle', 'slv', 'smr', 'som', 'srb', 'ssd', 'stp', 'sur', 'svk', 'svn', 'swe', 'swz', 'syc', 'syr', 'tcd', 'tgo', 'tha', 'tjk', 'tkm', 'tls', 'ton', 'tto', 'tun', 'tur', 'tuv', 'tza', 'uga', 'ukr', 'ury', 'usa', 'uzb', 'vct', 'ven', 'vnm', 'vut', 'wsm', 'yem', 'zaf', 'zmb', 'zwe' ), 'olympic' => array( 'abw', 'afg', 'ago', 'alb', 'and', 'are', 'arg', 'arm', 'asm', 'atg', 'aus', 'aut', 'aze', 'bdi', 'bel', 'ben', 'bfa', 'bgd', 'bgr', 'bhr', 'bhs', 'bih', 'blr', 'blz', 'bmu', 'bol', 'bra', 'brb', 'brn', 'btn', 'bwa', 'caf', 'can', 'che', 'chl', 'chn', 'civ', 'cmr', 'cod', 'cog', 'cok', 'col', 'com', 'cpv', 'cri', 'cub', 'cym', 'cyp', 'cze', 'deu', 'dji', 'dma', 'dnk', 'dom', 'dza', 'ecu', 'egy', 'eri', 'esp', 'est', 'eth', 'fin', 'fji', 'fra', 'fsm', 'gab', 'gbr', 'geo', 'gha', 'gin', 'gmb', 'gnb', 'gnq', 'grc', 'grd', 'gtm', 'gum', 'guy', 'hkg', 'hnd', 'hrv', 'hti', 'hun', 'idn', 'ind', 'irl', 'irn', 'irq', 'isl', 'isr', 'ita', 'jam', 'jor', 'jpn', 'kaz', 'ken', 'kgz', 'khm', 'kir', 'kna', 'kor', 'kwt', 'lao', 'lbn', 'lbr', 'lby', 'lca', 'lie', 'lka', 'lso', 'ltu', 'lux', 'lva', 'mar', 'mco', 'mda', 'mdg', 'mdv', 'mex', 'mhl', 'mkd', 'mli', 'mlt', 'mmr', 'mne', 'mng', 'moz', 'mrt', 'mus', 'mwi', 'mys', 'nam', 'ner', 'nga', 'nic', 'nld', 'nor', 'npl', 'nru', 'nzl', 'omn', 'pak', 'pan', 'per', 'phl', 'plw', 'png', 'pol', 'pri', 'prk', 'prt', 'pry', 'pse', 'qat', 'rou', 'rus', 'rwa', 'sau', 'sdn', 'sen', 'sgp', 'slb', 'sle', 'slv', 'smr', 'som', 'srb', 'stp', 'sur', 'svk', 'svn', 'swe', 'swz', 'syc', 'syr', 'tcd', 'tgo', 'tha', 'tjk', 'tkm', 'tls', 'ton', 'tto', 'tun', 'tur', 'tuv', 'twn', 'tza', 'uga', 'ukr', 'ury', 'usa', 'uzb', 'vct', 'ven', 'vir', 'vnm', 'vut', 'wsm', 'yem', 'zaf', 'zmb', 'zwe' ) ); private function __construct() {} public static function items() { return self::$items; } public static function groups() { return self::$groups; } } ?>
[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
Here is the function I used to sort the countries by label in french :
/** * Sort the data by label from Listo plugin (not handled in plugin yet) */ function sort_countries_by_label( $data, $options, $args ) { if ( ! $data ) return $data; usort( $data, 'compare' ); return $data; } function compare( $a, $b ) { if ( $a == $b ) return 0; for ( $i = 0, $l = min( mb_strlen( $a ), mb_strlen( $b ) ); $i < $l; $i++ ) { $cmp = compare_char( mb_substr( $a, $i, 1 ), mb_substr( $b, $i, 1 ) ); if ( $cmp != 0 ) { return $cmp; } } return (int) ( mb_strlen( $a ) > mb_strlen( $b ) ); } function compare_char( $a, $b ) { $chars = 'Aàá??BC?DEèéê?FGHIìí??JKLMNOòó???PQRSTUùú?üVWXYZ'; $chars .= 'aàá??bc?deèéê?fghiìí??jklmnoòó???pqrstuùú?üvwxyz'; $pos_a = mb_strpos( $chars, $a ); $pos_b = mb_strpos( $chars, $b ); if ( $pos_a === false ) return (int) ( false !== $pos_b ); return false === $pos_b ? -1 : ( $pos_a - $pos_b ); } add_filter( 'wpcf7_form_tag_data_option', 'sort_countries_by_label', 11, 3 );
- The topic ‘Alphabetical order countries’ is closed to new replies.