Add code snippet to add a country (#39850)

This commit is contained in:
Niels Lange 2023-08-23 22:39:22 +02:00 committed by GitHub
commit a22f637023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 8 deletions

View File

@ -2,11 +2,11 @@
Various code snippets you can add to your site to enable custom functionality:
- [Add a message above the login / register form](./before-login--register-form.md)
- [Add a currency and symbol](./add-a-currency-symbol.md)
- [Change number of related products output](./number-of-products-per-row.md)
- [Rename a country](./rename-a-country.md)
- [Change a currency symbol](./change-a-currency-symbol.md)
- [Unhook and remove WooCommerce emails](./unhook--remove-woocommerce-emails.md)
- [Unhook and remove WooCommerce emails](./unhook--remove-woocommerce-emails.md);
- [Adjust the quantity input values](./adjust-quantity-input-values.md)
- [Adjust the quantity input values](./adjust-quantity-input-values.md)
- [Add a country](./add-a-country.md)
- [Add a currency and symbol](./add-a-currency-symbol.md)
- [Add a message above the login / register form](./before-login--register-form.md)
- [Change a currency symbol](./change-a-currency-symbol.md)
- [Change number of related products output](./number-of-products-per-row.md)
- [Rename a country](./rename-a-country.md)
- [Unhook and remove WooCommerce emails](./unhook--remove-woocommerce-emails.md)

View File

@ -0,0 +1,38 @@
# Add a country
Add this code to your child themes `functions.php` file or via a plugin that allows custom functions to be added, such as the [Code Snippets](https://wordpress.org/plugins/code-snippets/) plugin. Avoid adding custom code directly to your parent themes functions.php file, as this will be wiped entirely when you update the theme.
```php
if ( ! function_exists( 'YOUR_PREFIX_add_country_to_countries_list' ) ) {
/**
* Add a country to countries list
*
* @param array $countries Existing country list.
* @return array $countries Modified country list.
*/
function YOUR_PREFIX_add_country_to_countries_list( $countries ) {
$new_countries = array(
'NIRE' => __( 'Northern Ireland', 'YOUR-TEXTDOMAIN' ),
);
return array_merge( $countries, $new_countries );
}
add_filter( 'woocommerce_countries', 'YOUR_PREFIX_add_country_to_countries_list' );
}
if ( ! function_exists( 'YOUR_PREFIX_add_country_to_continents_list' ) ) {
/**
* Add a country to continents list
*
* @param array $continents Existing continents list.
* @return array $continents Modified continents list.
*/
function YOUR_PREFIX_add_country_to_continents_list( $continents ) {
$continents['EU']['countries'][] = 'NIRE';
return $continents;
}
add_filter( 'woocommerce_continents', 'YOUR_PREFIX_add_country_to_continents_list' );
}
```