Skip to content

Instantly share code, notes, and snippets.

@rynaldos-zz
Last active July 2, 2020 05:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rynaldos-zz/a7fa2f812c85de055aff9ad6b1dcebe3 to your computer and use it in GitHub Desktop.
Save rynaldos-zz/a7fa2f812c85de055aff9ad6b1dcebe3 to your computer and use it in GitHub Desktop.
[WooCommerce 3.0+] Custom sorting for checkout page country dropdown
// 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