Skip to content

Instantly share code, notes, and snippets.

@jorpdesigns
Created July 15, 2021 12:12
Show Gist options
  • Save jorpdesigns/ed81df0190f8d48619ce99b275959e57 to your computer and use it in GitHub Desktop.
Save jorpdesigns/ed81df0190f8d48619ce99b275959e57 to your computer and use it in GitHub Desktop.
Snippet to reorder countries in dropdown on WooCommerce checkout form
<?php
// 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 country AND country name (example: US | United States or GB | United Kingdom (UK)
$countries = ['GB' => 'United Kingdom'] + ['US' => 'United States'] + ['CA' => 'Canada'] + $countries;
return $countries;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment