Add code snippet to add a currency and symbol (#39851)
This commit is contained in:
commit
5a74f2a31b
|
@ -3,5 +3,6 @@
|
||||||
Various code snippets you can add to your site to enable custom functionality:
|
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 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)
|
- [Change number of related products output](./number-of-products-per-row.md)
|
||||||
- [Unhook and remove WooCommerce emails](./unhook--remove-woocommerce-emails.md)
|
- [Unhook and remove WooCommerce emails](./unhook--remove-woocommerce-emails.md)
|
|
@ -0,0 +1,38 @@
|
||||||
|
# Add a currency and symbol
|
||||||
|
|
||||||
|
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_currency_name' ) ) {
|
||||||
|
/**
|
||||||
|
* Add custom currency
|
||||||
|
*
|
||||||
|
* @param array $currencies Existing currencies.
|
||||||
|
* @return array $currencies Updated currencies.
|
||||||
|
*/
|
||||||
|
function YOUR_PREFIX_add_currency_name( $currencies ) {
|
||||||
|
$currencies['ABC'] = __( 'Currency name', 'YOUR-TEXTDOMAIN' );
|
||||||
|
|
||||||
|
return $currencies;
|
||||||
|
}
|
||||||
|
add_filter( 'woocommerce_currencies', 'YOUR_PREFIX_add_currency_name' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'YOUR_PREFIX_add_currency_symbol' ) ) {
|
||||||
|
/**
|
||||||
|
* Add custom currency symbol
|
||||||
|
*
|
||||||
|
* @param string $currency_symbol Existing currency symbols.
|
||||||
|
* @param string $currency Currency code.
|
||||||
|
* @return string $currency_symbol Updated currency symbol(s).
|
||||||
|
*/
|
||||||
|
function YOUR_PREFIX_add_currency_symbol( $currency_symbol, $currency ) {
|
||||||
|
switch( $currency ) {
|
||||||
|
case 'ABC': $currency_symbol = '$'; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $currency_symbol;
|
||||||
|
}
|
||||||
|
add_filter('woocommerce_currency_symbol', 'YOUR_PREFIX_add_currency_symbol', 10, 2);
|
||||||
|
}
|
||||||
|
```
|
Loading…
Reference in New Issue