In a recent Business Bloomer Club Slack thread, a WooCommerce user wanted to translate the currency code “TWD” (Taiwan Dollar) into the Traditional Chinese symbol “新台幣.”
Since WPML does not handle currency symbols directly, an alternative solution is required.
Here’s how to customize WooCommerce currency symbols to display a translated version.
Solution: Use WooCommerce’s woocommerce_currency_symbol
Filter
WooCommerce provides a woocommerce_currency_symbol
filter that allows you to modify the currency symbol. This filter can change the currency label site-wide, making it ideal for translating currency codes.
Add the following code snippet to your theme’s functions.php
file:
add_filter( 'woocommerce_currency_symbol', 'custom_currency_symbol', 10, 2 );
function custom_currency_symbol( $currency_symbol, $currency ) {
if ( 'TWD' === $currency ) {
$currency_symbol = '新台幣'; // Traditional Chinese for Taiwan Dollar
}
return $currency_symbol;
}
Explanation of the Code
- Filter Application: The
woocommerce_currency_symbol
filter allows you to change the currency symbol dynamically. - Condition for TWD: This snippet checks if the currency is set to “TWD” (Taiwan Dollar). If so, it replaces “TWD” with the Traditional Chinese symbol “新台幣.”
Additional Considerations
- Multi-Currency Plugins: If you’re using a multi-currency plugin, ensure compatibility with the plugin to prevent overrides.
- Testing the Translation: Test the currency display across the site to confirm that the change appears consistently on product pages, checkout, and invoices.
Conclusion
By using WooCommerce’s woocommerce_currency_symbol
filter, you can easily translate currency codes into local symbols or text, ensuring a localized and user-friendly experience for your customers.