summaryrefslogtreecommitdiff
path: root/snippets/kudos-currency.php
blob: b524c0b3f65bc04cf2d2686c501f2db5bd8979e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * License: Public domain.
 *
 * Description: Snippets adding support for the KUDOS and TESTKUDOS currency.
 * Author Christian Grothoff <grothoff@taler.net>
 */

// See also https://gist.github.com/woogists/72947b71e48a62f15f5548283d4ed00f#file-wc-add-currency-symbol-php.
add_filter( 'woocommerce_currencies', 'add_my_currency' );


/**
 * Extend the list of currencies.
 *
 * @param array $currencies array with strings with the names of supported currencies.
 *
 * @return array with extended list of currencies.
 */
function add_my_currency( $currencies ) {
	$currencies['KUDOS']     = __( 'KUDOS', 'woocommerce' );
	$currencies['TESTKUDOS'] = __( 'TESTKUDOS', 'woocommerce' );
	return $currencies;
}


add_filter( 'woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2 );

/**
 * Lookup a currency symbol by the given currency.
 *
 * @param string $currency_symbol Symbol the currency was mapped to so far.
 * @param string $currency        Currency to map.
 *
 * @return desired currency symbol, usually the input, except for the two currencies we know.
 */
function add_my_currency_symbol( $currency_symbol, $currency ) {
	switch ( $currency ) {
		case 'KUDOS':
			$currency_symbol = 'ク';
			break;
		case 'TESTKUDOS':
			$currency_symbol = 'テ';
			break;
	}
	return $currency_symbol;
}