How to get a list of country codes in woocommerce?

by darrion.kuhn , in category: PHP CMS , 9 months ago

How to get a list of country codes in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cali_green , 9 months 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.

Related Threads:

How to get list of order id in woocommerce?
How to get only product list from woocommerce api?
How to add country and state in woocommerce?
How to remove specific country in woocommerce?
How to get country from ip in laravel?
How to list products by vendor id in woocommerce?