Support

Home Forums Add-ons User Submitted ACF Country field

Solved

ACF Country field

  • Hi,

    I needed a country field for a project I’m working on so I quickly developped an addon for this :
    https://github.com/nlemoine/acf-country

    This addon displays an ISO 3166-1 alpha 2 country list. Country names are available in every language and probably in your WordPress installation language.

    This plugin requires :
    – ACF v4+
    – PHP 5.3.3+

    Beware, the weight of this plugin is about 10mo.

    I plan to improve a little bit this plugin later for greater compatibility (ACF 3, etc.).

    Hope it will help someone else !

    • Elliot

    • January 7, 2014 at 10:17 am

    Hi @nlemoine

    Great work!

    Thanks
    E

    • Rneeson

    • November 17, 2014 at 1:10 pm

    I just downloaded the file and installed it all went good but when i went to insert the
    include_once(‘acf-country/acf-country.php’);
    into the php file it came up with an error and wont let me insert it?
    where do i insert it into the file sorry for being so stupid please see your code below thanks in advance

    <?php
    /*
    Plugin Name: Advanced Custom Fields: Country Field
    Plugin URI: https://github.com/Vheissu/acf-country-field
    Description: Adds a country as well as city/state field to your WordPress sites.
    Version: 1.0.0
    Author: Dwayne Charrington
    Author URI: http://dwaynecharrington.com
    License: GPL
    */

    class acf_field_country_plugin
    {

    public function __construct()
    {
    $domain = “acf-country-field”;
    $mofile = trailingslashit(dirname(__File__)) . ‘lang/’ . $domain . ‘-‘ . get_locale() . ‘.mo’;
    load_textdomain( $domain, $mofile );

    add_action(‘acf/register_fields’, array($this, ‘register_fields’));

    register_activation_hook( __FILE__, array($this, ‘populate_db’) );
    register_deactivation_hook( __FILE__, array($this, ‘depopulate_db’) );
    }

    public function register_fields()
    {
    include_once ‘register-fields.php’;
    }

    public function populate_db()
    {
    require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);

    ob_start();
    require_once “lib/install-data.php”;
    $sql = ob_get_clean();
    dbDelta( $sql );
    }

    public function depopulate_db()
    {
    require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);

    ob_start();
    require_once “lib/drop-tables.php”;
    $sql = ob_get_clean();
    dbDelta( $sql );
    }

    }

    new acf_field_country_plugin();

  • Hello,

    You’re adressing your issue to the wrong plugin. Check the Github URL in the first post.

  • Hi there,
    This is just what I needed. However, will this also work with ACF Pro?
    Thanks

    edit: Unfortunately it doesn’t work with ACF Pro

  • Unfortunately I can confirm that. When activating the plugin, an error occurs.

    Fatal error: Cannot redeclare composerRequire …

    It’s a pitty, this one would have been handy for me just now.

  • For this plugin: https://github.com/Vheissu/acf-country-field
    I have add ACF field to woocommerce product. Countries field is visible, country chosing works properly, but when save produkt and page reload country list looks like default view. Should display selected country. Not save selected country.

  • Hi,

    I just updated the plugin, it’s been improved and is now fully functionnal with ACF 4 & 5 (pro).

    You can check it here: https://github.com/nlemoine/acf-country

  • Hi,

    Works great on my site!

    Just a suggestion if you can add states for each country chosen.
    The 1st option to choose is country. Once country is chosen, only states from that chosen country appear for 2nd option.

    Thanks.

  • Hi,

    Sorry, this field aims to only display countries.

    Adding states would also involve some issues.
    States are a US administrative concept, they are called “lander” in Germany, “region” which has a subdivision called “departement”. At a world scale, it would be quite hard to handle every country specificities.

    If you want state option, you can install the other ACF country plugin: https://github.com/Vheissu/acf-country-field

    • Spen

    • November 2, 2017 at 9:13 am

    Great plugin @nlemoine – the country flags are not loading inside the select, though. Any idea? All of the assets appear to be loading correctly.

    Cheers 🙂

    • Beee

    • November 5, 2017 at 3:44 am

    Nice feature with the flags.

    For those of you that might be looking for a more extensive location selection, I’ve just released v0.1 of the ACF City Selector plugin where you can select a country, the a state (within that country) and then a city (within that state).

    Read more about it on http://acfcs.berryplasman.com

  • Wow, that looks impressive, Berry. I definitely keep an eye on this!

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.