Skip to content

Instantly share code, notes, and snippets.

@paullacey78
Created May 13, 2019 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paullacey78/8d55c67ccee1ab5c39f328b863dc4b2b to your computer and use it in GitHub Desktop.
Save paullacey78/8d55c67ccee1ab5c39f328b863dc4b2b to your computer and use it in GitHub Desktop.
<?php
/*
* Woocommerce Push UK & USA to the top of the country list
*/
add_filter('woocommerce_sort_countries', '__return_false');
add_filter( 'woocommerce_countries', 'change_country_order_in_checkout_form' );
function change_country_order_in_checkout_form($countries)
{
$uk = $countries['GB']; // Store the data for "UK key
unset($countries["GB"]); // Remove "UK entry from the array
$usa = $countries['US']; // Store the data for "US" key
unset($countries["US"]); // Remove "US" entry from the array
// Return "UK then US" first in the countries array
return array('GB' => $uk, 'US' => $usa ) + $countries;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment