Add a Custom Currency
Adds a currency that WooCommerce does not list, such as a local or loyalty currency, so you can select it in the general settings.
Opens WPIDE on
Code
$wpide_custom_currency = array(
'code' => 'XYZ', // Three-letter code.
'name' => 'Example Credits', // Name shown in settings.
'symbol' => 'Cr', // Symbol shown with prices.
);
add_filter( 'woocommerce_currencies', function ( $currencies ) use ( $wpide_custom_currency ) {
$currencies[ $wpide_custom_currency['code'] ] = $wpide_custom_currency['name'];
return $currencies;
} );
add_filter( 'woocommerce_currency_symbol', function ( $symbol, $currency ) use ( $wpide_custom_currency ) {
return $currency === $wpide_custom_currency['code'] ? $wpide_custom_currency['symbol'] : $symbol;
}, 10, 2 );
Notes
After activating, choose the new currency in WooCommerce > Settings > General. Payment gateways may not support custom currencies.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.