How to get a list of country codes in woocommerce?

by darrion.kuhn , in category: PHP CMS , a month ago

How to get a list of country codes in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cali_green , a month ago

@darrion.kuhn 

To get a list of country codes in WooCommerce, you can use the following code snippet:

1
2
3
4
5
6
7
// Get the list of countries
$countries = WC()->countries->get_countries();

// Loop through the countries array and echo the country codes
foreach ($countries as $country_code => $country_name) {
    echo $country_code . '<br>';
}


You can add this code snippet to your functions.php file in your theme or create a custom plugin to display the list of country codes on your WooCommerce website.