Add a country
This commit is contained in:
parent
cb2cf79342
commit
b1f3596903
|
@ -3,5 +3,6 @@
|
|||
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 country](./add-a-country.md)
|
||||
- [Change number of related products output](./number-of-products-per-row.md)
|
||||
- [Unhook and remove WooCommerce emails](./unhook--remove-woocommerce-emails.md)
|
|
@ -0,0 +1,39 @@
|
|||
# Add a country
|
||||
|
||||
> This is a **Developer level** doc. If you are unfamiliar with code and resolving potential conflicts, select a [WooExpert or Developer](https://woocommerce.com/customizations/) for assistance. We are unable to provide support for customizations under our [Support Policy](http://www.woocommerce.com/support-policy/).
|
||||
|
||||
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 [Code Snippets](https://wordpress.org/plugins/code-snippets/) plugin. Avoid adding custom code directly to your parent theme’s 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', 'woocommerce' ),
|
||||
);
|
||||
|
||||
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' );
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue