Last active
July 2, 2020 05:27
-
-
Save rynaldos-zz/a7fa2f812c85de055aff9ad6b1dcebe3 to your computer and use it in GitHub Desktop.
[WooCommerce 3.0+] Custom sorting for checkout page country dropdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// disable woocommerce sorting | |
add_filter( 'woocommerce_sort_countries', '__return_false' ); | |
add_filter( 'woocommerce_countries', 'wc_custom_countries_order', 10, 1 ); | |
function wc_custom_countries_order( $countries ) { | |
// replace with iso code of the country (example: US or GB) | |
unset($countries['country_1_iso_code']); | |
unset($countries['country_2_iso_code']); | |
unset($countries['country_3_iso_code']); | |
// replace with iso code of country AND country name (example: US | United States or GB | United Kingdom (UK) | |
$countries = ['country_1_iso' => 'country_1_name'] + ['country_2_iso' => 'country_2_name'] + ['country_3_iso' => 'country_3_name'] + $countries; | |
return $countries; | |
} | |
// Did this help? Donate me some BTC: 1BEsm8VMkYhSFJ92cvUYwxCtsfsB2rBfiG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment