Title: Shipping Zone Error
Last modified: January 11, 2025

---

# Shipping Zone Error

 *  Resolved [mohammedmalleck](https://wordpress.org/support/users/mohammedmalleck/)
 * (@mohammedmalleck)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/shipping-zone-error-2/)
 * Hi , so I was looking at the debug.php file & I realised that I have some Shipping
   class zones errors which I cannot how to *fix*.
   The errors are these **Undefined
   array key “MK/ST/KS/GB-NIR” in /wp-content/plugins/woocommerce/includes/class-
   wc-shipping-zone.php on line 125**FYI , I am using the below code in funcitions.
   php to make sure only the countries I allow are used in places where woocomerce
   adds countries , ps:. the priority is to have control over which countries are
   shown in countries field in woocomerce checkout page.
 *     ```wp-block-code
       // Filter allowed countriesadd_filter('woocommerce_countries', 'filter_allowed_countries');function filter_allowed_countries($countries) {    $allowed_countries = array(        'AE' => 'United Arab Emirates',        'OM' => 'Oman',        'PK' => 'Pakistan',        'QA' => 'Qatar',        'BH' => 'Bahrain',        'BD' => 'Bangladesh',        'SA' => 'Saudi Arabia',        'LK' => 'Sri Lanka',        'IN' => 'India',        'KW' => 'Kuwait',        'LB' => 'Lebanon',        'LY' => 'Libya',        'AT' => 'Austria',        'AU' => 'Australia',        'AZ' => 'Azerbaijan',        'FR' => 'France',        'GE' => 'Georgia',        'DE' => 'Germany',        'MC' => 'Monaco',        'MY' => 'Malaysia',        'MO' => 'Macao',        'LI' => 'Liechtenstein',        'CY' => 'Cyprus',        'DK' => 'Denmark',        'KZ' => 'Kazakhstan',        'JO' => 'Jordan',        'IT' => 'Italy',        'NL' => 'Netherlands',        'PH' => 'Philippines',        'PT' => 'Portugal',        'CH' => 'Switzerland',        'TW' => 'Taiwan',        'TH' => 'Thailand',        'UZ' => 'Uzbekistan',        'VA' => 'Vatican',        'BE' => 'Belgium',        'EG' => 'Egypt',        'GR' => 'Greece',        'SG' => 'Singapore',        'ES' => 'Spain',        'BN' => 'Brunei',        'HK' => 'Hong Kong',        'ID' => 'Indonesia',        'KR' => 'South Korea',        'NP' => 'Nepal',        'NG' => 'Nigeria',        'PL' => 'Poland',        'SE' => 'Sweden',        'TR' => 'Turkey',        'US' => 'United States',        'ET' => 'Ethiopia',        'GH' => 'Ghana',        'GA' => 'Gabon',        'MG' => 'Madagascar',        'MT' => 'Malta',        'MU' => 'Mauritius',        'MZ' => 'Mozambique',        'RW' => 'Rwanda',        'SO' => 'Somalia',        'SD' => 'Sudan',        'CN' => 'China',        'KE' => 'Kenya',        'PS' => 'Palestinian Territory',        'TZ' => 'Tanzania',        'TN' => 'Tunisia',        'UG' => 'Uganda',        'DJ' => 'Djibouti',        'LS' => 'Lesotho',        'ZM' => 'Zambia',        'ZW' => 'Zimbabwe',        'AM' => 'Armenia',        'BJ' => 'Benin',        'LU' => 'Luxembourg',        'MW' => 'Malawi',        'ML' => 'Mali',        'MA' => 'Morocco',        'SL' => 'Sierra Leone',        'ZA' => 'South Africa',        'BF' => 'Burkina Faso',        'CA' => 'Canada',        'CG' => 'Congo (Brazzaville)',        'CZ' => 'Czech Republic',        'GN' => 'Guinea',        'KG' => 'Kyrgyzstan',        'NA' => 'Namibia',        'NZ' => 'New Zealand',        'TG' => 'Togo',        'UA' => 'Ukraine',        'VN' => 'Vietnam',        'LR' => 'Liberia',        'RU' => 'Russia',        'SY' => 'Syria',        'AL' => 'Albania',        'AD' => 'Andorra',        'AO' => 'Angola',        'EE' => 'Estonia',        'FO' => 'Faroe Islands',        'GI' => 'Gibraltar',        'GL' => 'Greenland',        'LT' => 'Lithuania',        'MV' => 'Maldives',        'MD' => 'Moldova',        'SM' => 'San Marino',        'SN' => 'Senegal',        'SC' => 'Seychelles',        'SK' => 'Slovakia',        'SI' => 'Slovenia',        'BA' => 'Bosnia and Herzegovina',        'BW' => 'Botswana',        'BI' => 'Burundi',        'KH' => 'Cambodia',        'HR' => 'Croatia',        'HU' => 'Hungary',        'IQ' => 'Iraq',        'IE' => 'Ireland',        'IM' => 'Isle of Man',        'CI' => 'Ivory Coast',        'JP' => 'Japan',        'LA' => 'Laos',        'LV' => 'Latvia',        'MM' => 'Myanmar',        'SZ' => 'Eswatini',        'TJ' => 'Tajikistan',        'TM' => 'Turkmenistan',        'YE' => 'Yemen',        'DZ' => 'Algeria',        'AS' => 'American Samoa',        'AI' => 'Anguilla',        'AG' => 'Antigua and Barbuda',        'AR' => 'Argentina',        'AW' => 'Aruba',        'BS' => 'Bahamas',        'BB' => 'Barbados',        'BY' => 'Belarus',        'BZ' => 'Belize',        'BM' => 'Bermuda',        'BT' => 'Bhutan',        'BO' => 'Bolivia',        'TL' => 'Timor-Leste',        'EC' => 'Ecuador',        'SV' => 'El Salvador',        'GQ' => 'Equatorial Guinea',        'FK' => 'Falkland Islands',        'FJ' => 'Fiji',        'FI' => 'Finland',        'GF' => 'French Guiana',        'PF' => 'French Polynesia',        'GM' => 'Gambia',        'GD' => 'Grenada',        'GP' => 'Guadeloupe',        'MH' => 'Marshall Islands',        'MQ' => 'Martinique',        'MR' => 'Mauritania',        'YT' => 'Mayotte',        'MX' => 'Mexico',        'MN' => 'Mongolia',        'ME' => 'Montenegro',        'MS' => 'Montserrat',        'WS' => 'Samoa',        'RS' => 'Serbia',        'SB' => 'Solomon Islands',        'PM' => 'Saint Pierre and Miquelon',        'KN' => 'Saint Kitts and Nevis',        'LC' => 'Saint Lucia',        'VC' => 'Saint Vincent and the Grenadines',        'SR' => 'Suriname',        'SJ' => 'Svalbard and Jan Mayen',        'BR' => 'Brazil',        'BG' => 'Bulgaria',        'CV' => 'Cape Verde',        'KY' => 'Cayman Islands',        'CF' => 'Central African Republic',        'CL' => 'Chile',        'CX' => 'Christmas Island',        'CC' => 'Cocos (Keeling) Islands',        'CO' => 'Colombia',        'KM' => 'Comoros',        'CK' => 'Cook Islands',        'CR' => 'Costa Rica',        'CU' => 'Cuba',        'GU' => 'Guam',        'GT' => 'Guatemala',        'GW' => 'Guinea-Bissau',        'GY' => 'Guyana',        'HT' => 'Haiti',        'HN' => 'Honduras',        'IS' => 'Iceland',        'JM' => 'Jamaica',        'KI' => 'Kiribati',        'NR' => 'Nauru',        'NC' => 'New Caledonia',        'NI' => 'Nicaragua',        'NE' => 'Niger',        'NF' => 'Norfolk Island',        'MP' => 'Northern Mariana Islands',        'NO' => 'Norway',        'PW' => 'Belau',        'PA' => 'Panama',        'PG' => 'Papua New Guinea',        'PY' => 'Paraguay',        'PE' => 'Peru',        'PN' => 'Pitcairn',        'PR' => 'Puerto Rico',        'TO' => 'Tonga',        'TT' => 'Trinidad and Tobago',        'TC' => 'Turks and Caicos Islands',        'TV' => 'Tuvalu',        'UY' => 'Uruguay',        'VU' => 'Vanuatu',        'VE' => 'Venezuela',        'VG' => 'Virgin Islands (British)',        'VI' => 'Virgin Islands (US)',        'EH' => 'Western Sahara',        'DM' => 'Dominica',        'DO' => 'Dominican Republic',        'RE' => 'Reunion',        'RO' => 'Romania',        'GB' => 'United Kingdom', // Added United Kingdom        'GB-NIR' => 'Northern Ireland'     );    // Filter the countries array to only include allowed countries    return array_intersect_key($countries, $allowed_countries);}
       ```
   
 * Maybe something in the above code is causing the issue but I am not sure what
   is , and how to solve it…
   Will appreciate any help. Ty!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Mahfuzur Rahman](https://wordpress.org/support/users/mahfuzurwp/)
 * (@mahfuzurwp)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/shipping-zone-error-2/#post-18238638)
 * Hi [@mohammedmalleck](https://wordpress.org/support/users/mohammedmalleck/),
 * The issue is likely caused by the custom filter_allowed_countries function, which
   filters WooCommerce countries. WooCommerce uses specific codes for regions, such
   as “GB-NIR” for Northern Ireland, in shipping zones. If these region codes are
   not properly included in the $allowed_countries array returned by your filter,
   it results in the “Undefined array key” error. To resolve this, ensure all region
   codes used by WooCommerce, like “GB-NIR,” are correctly defined in your array.
 * As this involves custom code, I understand it can feel a bit tricky to navigate.
   I recommend reaching out to a developer who can carefully review and adjust your
   code to ensure it works seamlessly with WooCommerce.
 * Thank you.
 *  Thread Starter [mohammedmalleck](https://wordpress.org/support/users/mohammedmalleck/)
 * (@mohammedmalleck)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/shipping-zone-error-2/#post-18239211)
 * Hi [@mahfuzurwp](https://wordpress.org/support/users/mahfuzurwp/) ,
   So I added
   these countires in the list
 *     ```wp-block-code
              'GB-NIR' => 'Northern Ireland',        'ST' => 'Scotland',        'MK' => 'Macedonia',        'KS' => 'Kansas'
       ```
   
 * Now I only get error for** ‘GB-NIR’** & **‘KS’** in **debug.log** file. File 
   error below :
 *     ```wp-block-code
       [12-Jan-2025 12:50:04 UTC] PHP Warning:  Undefined array key "GB-NIR" in /wp-content/plugins/woocommerce/includes/class-wc-shipping-zone.php on line 125[12-Jan-2025 12:50:04 UTC] PHP Warning:  Undefined array key "KS" in /wp-content/plugins/woocommerce/includes/class-wc-shipping-zone.php on line 125
       ```
   
 * I am aware of code to a good extent , I would just like some support from the
   woocomerce support team on **how I can modify my code **such that it does not
   cause errors with woocomerce pre-written code. Let me know if that help is possible.
   Ty!
 *  [Moses M. (woo-hc)](https://wordpress.org/support/users/mosesmedh/)
 * (@mosesmedh)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/shipping-zone-error-2/#post-18239358)
 * Hi [@mohammedmalleck](https://wordpress.org/support/users/mohammedmalleck/),
 * I’m glad to hear you’re getting the hang of it. While we’re happy to assist with
   core WooCommerce issues on this forum, support for custom code and customization
   falls outside our scope.
 * You can join the [WooCommerce community channel](https://woocommerce.com/community-slack/)
   for further help or consider hiring a developer to assist with this.
 *  [Saif](https://wordpress.org/support/users/babylon1999/)
 * (@babylon1999)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/shipping-zone-error-2/#post-18239511)
 * Hello [@mohammedmalleck](https://wordpress.org/support/users/mohammedmalleck/)!
 * > The errors are these
   > **Undefined array key “MK/ST/KS/GB-NIR” in /wp-content/
   > plugins/woocommerce/includes/class-wc-shipping-zone.php on line 125**
 * This is expected because you’re introducing countries that WooCommerce doesn’t
   recognize. 
   First, to change the list of countries that appear in the checkout,
   you don’t need a snippet at all. Simply navigate to `WooCommerce -> Settings -
   > General -> Sell to specific countries` and select those countries from there.
 * As for adding your own countries, such as Northern Ireland and Scotland, you 
   need to append your array to the existing one. Here’s an example:
 *     ```wp-block-code
       /** * Add a new country to countries list */add_filter( 'woocommerce_countries',  'handsome_bearded_guy_add_my_country' );function handsome_bearded_guy_add_my_country( $countries ) {  $new_countries = array(	   'KS'  => __( 'Kansas', 'woocommerce' ),	   'GB-NIR'  => __( 'Northern Ireland', 'woocommerce' ),	   'ST'  => __( 'Scotland', 'woocommerce' ),	   'MK'  => __( 'Macedonia', 'woocommerce' ),	                    );	return array_merge( $countries, $new_countries );}
       ```
   
 * You should also assign these countries a content so that you can select them 
   in the shipping settings. 
 *     ```wp-block-code
       add_filter( 'woocommerce_continents', 'handsome_bearded_guy_add_my_country_to_continents' );function handsome_bearded_guy_add_my_country_to_continents( $continents ) {	$continents['EU']['countries'][] = 'GB-NIR';	$continents['EU']['countries'][] = 'ST';	$continents['EU']['countries'][] = 'MK';	$continents['NA']['countries'][] = 'KS';	return $continents;}
       ```
   
 * Cheers!
 *  Thread Starter [mohammedmalleck](https://wordpress.org/support/users/mohammedmalleck/)
 * (@mohammedmalleck)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/shipping-zone-error-2/#post-18240076)
 * Hi [@babylon1999](https://wordpress.org/support/users/babylon1999/) !,
   Thanks
   for the help , but here’s the thing. I have a lot of countries to sell to & adding
   them manually via the `WooCommerce -> Settings -> General -> Sell to specific
   countries` sounds too long to me..from what I was able to deduce some of the 
   countries WooCommerce sells to is not where I want to sell hence selecting `all
   countries` is not the solution also.So I decided to go a step ahead and only 
   allow the countries I want to sell to and then select `all countries` in WooCommerce.
   However it is not proving to be ideal as of now.What would be your take to solve
   this?
 *  [Moses M. (woo-hc)](https://wordpress.org/support/users/mosesmedh/)
 * (@mosesmedh)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/shipping-zone-error-2/#post-18240574)
 * Hi [@mohammedmalleck](https://wordpress.org/support/users/mohammedmalleck/),
 * Additionally, there’s an option to sell to all countries except for specific 
   ones. This allows you to exclude the countries you don’t wish to sell to. You
   can check if this option suits your needs. If not, you may want to consider getting
   professional help or hiring certified WooCommerce developers from here: [https://woocommerce.com/development-services/](https://woocommerce.com/development-services/)

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Shipping Zone Error’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 6 replies
 * 4 participants
 * Last reply from: [Moses M. (woo-hc)](https://wordpress.org/support/users/mosesmedh/)
 * Last activity: [1 year, 3 months ago](https://wordpress.org/support/topic/shipping-zone-error-2/#post-18240574)
 * Status: resolved