Skip to content

Instantly share code, notes, and snippets.

@sajdoko
Created August 22, 2023 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajdoko/78f9c4de2a213986a5269c345f82c64b to your computer and use it in GitHub Desktop.
Save sajdoko/78f9c4de2a213986a5269c345f82c64b to your computer and use it in GitHub Desktop.
Add Kosovo as a checkout country in WooCommerce
<?php
// Add Kosovo as a checkout country
add_filter('woocommerce_countries', 'snippetpress_add_kosovo');
function snippetpress_add_kosovo($countries) {
// Add Kosovo to the list of countries
$countries['XK'] = __('Kosovo', 'woocommerce');
return $countries;
}
// Add Kosovo to the list of continents (EU)
add_filter('woocommerce_continents', 'snippetpress_add_kosovo_to_continents');
function snippetpress_add_kosovo_to_continents($continents) {
// Add Kosovo to the list of European countries
$continents['EU']['countries'][] = 'XK';
return $continents;
}
// Add states (cities) for Kosovo
add_filter('woocommerce_states', 'add_kosovo_states');
function add_kosovo_states($states) {
// Define the states (cities) in Kosovo
$states['XK'] = array(
'' => __('Your State Name', 'woocommerce'), // Replace with your own state name
'pristina' => __('Pristina', 'woocommerce'),
'peja' => __('Peja', 'woocommerce'),
'prizren' => __('Prizren', 'woocommerce'),
'mitrovica' => __('Mitrovica', 'woocommerce'),
'gjilan' => __('Gjilan', 'woocommerce'),
'gjakova' => __('Gjakova', 'woocommerce'),
'ferizaj' => __('Ferizaj', 'woocommerce'),
// Add more cities here
);
return $states;
}
// Implementation Steps:
// 1 - Copy the entire code from this Gist.
// 2 - Log in to your WordPress admin panel.
// 3 - Go to "Appearance" > "Theme Editor."
// 4 - Open the functions.php file for editing. If you're using a child theme, make sure you're editing the child theme's functions.php file.
// 5 - Paste the copied code at the end of the functions.php file.
// 6 - Modify the state names and cities within the add_kosovo_states function according to your requirements.
// 7 - Save the changes.
// Your website should now have Kosovo added as a checkout country with the specified states (cities).
// Remember that modifying theme files directly can be risky, especially if you're not familiar with PHP and WordPress.
// It's recommended to create a backup of your website or use a child theme to make these changes safely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment