-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

WooCommerce Cookbook
By :

WooCommerce has dozens of currencies already included in the plugin, including but not limited to US dollars, euros, British pounds, New Zealand dollars, Russian rubles, South African rands, Egyptian pounds, and the Mexican peso. If you are planning on using any of these currencies, you don't need to add your own currency and can skip this recipe. If you can't find your currency under WooCommerce | Settings | Currency, then you should follow the steps that follow to add it in.
We'll be writing some code to add your custom currency. You'll need a text editor to write the code and an FTP program to upload it to your site once we're done.
We're going to write a very small snippet and add it to WooCommerce. Once it's added, we'll select the currency from the Currency dropdown in the WooCommerce settings pages. The following are the steps that illustrate the process of creating custom currencies:
functions.php
file, located at wp-content/themes/your-theme-name/functions.php
, with your text editor.add_filter( 'woocommerce_currencies', 'add_patricks_currency' ); add_filter( 'woocommerce_currency_symbol', 'add_patricks_currency_symbol', 10, 2 );
Patrick's Currency
in the snippet that follows. You'll also need the three-character ISO code of the currency, which can be found at http://en.wikipedia.org/wiki/ISO_4217. This can replace PC
in the following code snippet:function add_patricks_currency( $currencies ) { $currencies['PC'] = __( 'Patrick's Currency', 'your-theme-name' ); return $currencies; }
function add_patricks_currency_symbol( $currency_symbol, $currency ) { switch( $currency ) { case 'PC': $currency_symbol = 'PC'; break; } return $currency_symbol; }
At this point, WooCommerce should know both your currency and your currency symbol, so it's worth uploading it and making sure we did it right. Upload the file via FTP.
Navigate to the Currency settings by going to WooCommerce | Settings. You should see your new currency in the Currency dropdown:
WooCommerce is filled with hooks—places where developers can add or modify the existing code. WooCommerce was smartly built so that anyone can use these hooks to add (or remove) any number of currencies. In this case, we used a filter which is a special type of hook to change the value of something. We changed the contents in an array.
In future recipes, we'll be using actions, which allow completely new programming to fire, and not just changing the value of something.
functions.php
file. That works, but it's not as bulletproof as putting it in its own WooCommerce plugin. Refer to the preceding recipe, Creating a WooCommerce plugin, for more details.