WooCommerce Custom Currency Generator
Add a currency WooCommerce does not ship with, or change an existing symbol, name and price format, with the filters that make it stick.
<?php
/**
* The BDT currency.
*/
/**
* Adds the currency to the list in WooCommerce settings.
*
* @param array $currencies Currency code to name.
* @return array
*/
function my_store_add_currency( $currencies ) {
$currencies['BDT'] = __( 'Bangladeshi Taka', 'my-store' );
return $currencies;
}
add_filter( 'woocommerce_currencies', 'my_store_add_currency' );
/**
* Sets the symbol printed with every price.
*
* @param string $symbol Current symbol.
* @param string $currency Currency code being formatted.
* @return string
*/
function my_store_currency_symbol( $symbol, $currency ) {
if ( 'BDT' === $currency ) {
$symbol = '৳';
}
return $symbol;
}
add_filter( 'woocommerce_currency_symbol', 'my_store_currency_symbol', 10, 2 );
/**
* Puts the symbol where this currency expects it, whatever the store setting says.
*
* @param string $format Current sprintf format.
* @param string $position Position from the WooCommerce setting.
* @return string
*/
function my_store_price_format( $format, $position ) {
if ( 'BDT' !== get_woocommerce_currency() ) {
return $format;
}
return '%1$s %2$s';
}
add_filter( 'woocommerce_price_format', 'my_store_price_format', 10, 2 );
Output is valid and updates as you type.
Fix the highlighted fields to update the output.
Add a currency WooCommerce does not ship with, or fix the symbol and position of one it does, with the three filters that actually control how a price is printed.
How to use
- Use the real ISO 4217 code. Payment gateways, tax services and accounting exports all match on it, and an invented code fails at the gateway.
- Paste the real symbol rather than an HTML entity. WooCommerce escapes output, so
৳shows up as those characters on the page. - Turn off “add it to the list” if the currency already exists and you only want a different symbol or position.
- Force the format only when this currency needs a different position from the rest of the store. The store setting applies to every currency at once.
- Set the decimal places before taking orders. Changing it later does not rewrite totals already stored.
Example
Adding a currency and putting its symbol on the left with a space:
function acme_add_currency( $currencies ) {
$currencies['BDT'] = __( 'Bangladeshi Taka', 'acme' );
return $currencies;
}
add_filter( 'woocommerce_currencies', 'acme_add_currency' );
function acme_currency_symbol( $symbol, $currency ) {
if ( 'BDT' === $currency ) {
$symbol = '৳';
}
return $symbol;
}
add_filter( 'woocommerce_currency_symbol', 'acme_currency_symbol', 10, 2 );
Adding the currency does not select it. Pick it in WooCommerce, Settings, General once the snippet is active.
Pitfalls
- Adding a currency does not make a gateway accept it. Stripe, PayPal and the rest each publish their own list, and an unsupported currency fails at payment.
- The symbol filter needs
10, 2to receive the currency code. Without it you change the symbol for every currency at once. woocommerce_price_formatruns for the active currency only in the generated code. Without the code check, one currency’s format leaks into all of them.- Changing decimal places does not touch stored order totals. Old orders keep the precision they were created with, which shows up in reports.
- Exchange rates are not part of this. WooCommerce stores one currency; multi currency needs a plugin that converts and stores rates.
- An invented currency code breaks tax services and CSV exports that validate against ISO 4217.
in the price format is intentional: a normal space lets the symbol wrap onto its own line.- Some themes format prices themselves. If the symbol is right in the cart and wrong on the product page, look at the theme first.
Compatibility
woocommerce_currencies, woocommerce_currency_symbol, woocommerce_price_format and wc_get_price_decimals have been stable since WooCommerce 2.4 and still apply in WooCommerce 8 and 9, including the cart and checkout blocks, which format prices through the same helpers. The generated code targets PHP 7.0 and up, and the tool runs entirely in your browser.