Reputation: 11
Hope to find a solution here.
I'd like to add a custom top-10 country list to the woocommerce (checkout) country dropdown list. So it should look like:
Top 10 countries Netherlands Germany Belgium UK USA
Select your country normal list
I couldn't find any a filter for this, only to add one or more countries.
Upvotes: 0
Views: 1891
Reputation: 139
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)
{
$usa = $countries['US']; // Store the data for "US" key
$uk = $countries['GB']; // Store the data for "UK" key
// Return "US" and "UK" first in the countries array
return array('US' => $usa, 'GB' => $uk) + $countries;
}
However, this removes the countries from the main list as well.
Upvotes: 1
Reputation: 182
Tray like this. This is working correctly for me.
https://www.wpstud.io/add-custom-select-field-woocommerce-checkout-page/
Upvotes: 0