Add UK postal counties to WooCommerce

This snippet adds UK postal counties to WooCommerce’s list of states.

Add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Dessky Snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be overwritten completely when you update the theme.

function  wc_uk_counties_add_counties( $states ) {

    $states['GB'] = array(
                            'AV' => 'Avon',
                            'BE' => 'Bedfordshire',
                            'BK' => 'Berkshire',
                            'BU' => 'Buckinghamshire',
                            'CA' => 'Cambridgeshire',
                            'CH' => 'Cheshire',
                            'CL' => 'Cleveland',
                            'CO' => 'Cornwall',
                            'CD' => 'County Durham',
                            'CU' => 'Cumbria',
                            'DE' => 'Derbyshire',
                            'DV' => 'Devon',
                            'DO' => 'Dorset',
                            'ES' => 'East Sussex',
                            'EX' => 'Essex',
                            'GL' => 'Gloucestershire',
                            'HA' => 'Hampshire',
                            'HE' => 'Herefordshire',
                            'HT' => 'Hertfordshire',
                            'IW' => 'Isle of Wight',
                            'KE' => 'Kent',
                            'LA' => 'Lancashire',
                            'LE' => 'Leicestershire',
                            'LI' => 'Lincolnshire',
                            'LO' => 'London',
                            'ME' => 'Merseyside',
                            'MI' => 'Middlesex',
                            'NO' => 'Norfolk',
                            'NH' => 'North Humberside',
                            'NY' => 'North Yorkshire',
                            'NS' => 'Northamptonshire',
                            'NL' => 'Northumberland',
                            'NT' => 'Nottinghamshire',
                            'OX' => 'Oxfordshire',
                            'SH' => 'Shropshire',
                            'SO' => 'Somerset',
                            'SM' => 'South Humberside',
                            'SY' => 'South Yorkshire',
                            'SF' => 'Staffordshire',
                            'SU' => 'Suffolk',
                            'SR' => 'Surrey',
                            'TW' => 'Tyne and Wear',
                            'WA' => 'Warwickshire',
                            'WM' => 'West Midlands',
                            'WS' => 'West Sussex',
                            'WY' => 'West Yorkshire',
                            'WI' => 'Wiltshire',
                            'WO' => 'Worcestershire',
                            'ABD' => 'Scotland / Aberdeenshire',
                            'ANS' => 'Scotland / Angus',
                            'ARL' => 'Scotland / Argyle & Bute',
                            'AYR' => 'Scotland / Ayrshire',
                            'CLK' => 'Scotland / Clackmannanshire',
                            'DGY' => 'Scotland / Dumfries & Galloway',
                            'DNB' => 'Scotland / Dunbartonshire',
                            'DDE' => 'Scotland / Dundee',
                            'ELN' => 'Scotland / East Lothian',
                            'EDB' => 'Scotland / Edinburgh',
                            'FIF' => 'Scotland / Fife',
                            'GGW' => 'Scotland / Glasgow',
                            'HLD' => 'Scotland / Highland',
                            'LKS' => 'Scotland / Lanarkshire',
                            'MLN' => 'Scotland / Midlothian',
                            'MOR' => 'Scotland / Moray',
                            'OKI' => 'Scotland / Orkney',
                            'PER' => 'Scotland / Perth and Kinross',
                            'RFW' => 'Scotland / Renfrewshire',
                            'SB' => 'Scotland / Scottish Borders',
                            'SHI' => 'Scotland / Shetland Isles',
                            'STI' => 'Scotland / Stirling',
                            'WLN' => 'Scotland / West Lothian',
                            'WIS' => 'Scotland / Western Isles',
                            'AGY' => 'Wales / Anglesey',
                            'GNT' => 'Wales / Blaenau Gwent',
                            'CP' => 'Wales / Caerphilly',
                            'CF' => 'Wales / Cardiff',
                            'CAE' => 'Wales / Carmarthenshire',
                            'CR' => 'Wales / Ceredigion',
                            'CW' => 'Wales / Conwy',
                            'DEN' => 'Wales / Denbighshire',
                            'FLN' => 'Wales / Flintshire',
                            'GLA' => 'Wales / Glamorgan',
                            'GWN' => 'Wales / Gwynedd',
                            'MT' => 'Wales / Merthyr Tydfil',
                            'MON' => 'Wales / Monmouthshire',
                            'PT' => 'Wales / Neath Port Talbot',
                            'NP' => 'Wales / Newport',
                            'PEM' => 'Wales / Pembrokeshire',
                            'POW' => 'Wales / Powys',
                            'RT' => 'Wales / Rhondda Cynon Taff',
                            'SS' => 'Wales / Swansea',
                            'TF' => 'Wales / Torfaen',
                            'WX' => 'Wales / Wrexham',
                            'ANT' => 'Northern Ireland / County Antrim',
                            'ARM' => 'Northern Ireland / County Armagh',
                            'DOW' => 'Northern Ireland / County Down',
                            'FER' => 'Northern Ireland / County Fermanagh',
                            'LDY' => 'Northern Ireland / County Londonderry',
                            'TYR' => 'Northern Ireland / County Tyrone',
                           );
    return $states;

}

add_filter( 'woocommerce_states', 'wc_uk_counties_add_counties' );
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...Loading...
Oopps, sorry. This discussion is closed.

If you are a paying customer and you are looking for Tech Support please post a ticket on our Support Tickets page and we will respond promptly.

If you are not a paying customer and you would like to post a pre-sale question or a quote request please use our Contact form.

Why did we close the discussion?

Many of the customers started reporting issues as comments instead of the ticketing system and this started delaying our response time.

We are making this change to serve our customers better. We have ramped up our support team and we are trying to get the reply out on the same day.

Thanks for understanding.

krolick_sqc rindalchadwick munster.jamila@mailxu.com