Skip to content
Advertisement

Make US first in Woocommerce checkout countries select field

I already have US selected as my default country in the woocommerce checkout. In addition to that, I was asked to move ‘US’ to the very top of the country list in the checkout form.

I created a new filter and hooked into ‘woocommerce_countries’ hook like this:

JavaScript

My list of countries gets modified correctly, but then something in WooCommerce sorts the countries alphabetically and I want to avoid that. I tried adding:

JavaScript

but that did not seem to make any difference. Any help is appreciated.

Advertisement

Answer

To avoid ordering, you need to use woocommerce_sort_countries filter hook this way:

JavaScript

And to set “US” first, try this instead:

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.

enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement