0
votes

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.

2
What have you tried so far... please show your code and post the problem rather than asking for prepared solutionmhasan
@mhasan: I tried things like this, but it only adds a country: function woo_add_my_country( $country ) { $country["AE-DU"] = 'Dubai'; return $country; } add_filter( 'woocommerce_countries', 'woo_add_my_country', 10, 1 );Roy Kosmeijer

2 Answers

1
votes
    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.