summaryrefslogtreecommitdiff
path: root/snippets/kudos-currency.php
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-10-19 19:25:44 +0200
committerChristian Grothoff <christian@grothoff.org>2020-10-19 19:25:44 +0200
commit7dd39f852aa1fc42d6d3b1f70bfce1605fa0e90e (patch)
treec2dbaeacdf3f1831dcc3a7716ae47d30aa092d8b /snippets/kudos-currency.php
parent051ca7e41d2fbad9f18fec76c314670bcd6a27f4 (diff)
downloadwoocommerce-taler-7dd39f852aa1fc42d6d3b1f70bfce1605fa0e90e.tar.gz
woocommerce-taler-7dd39f852aa1fc42d6d3b1f70bfce1605fa0e90e.tar.bz2
woocommerce-taler-7dd39f852aa1fc42d6d3b1f70bfce1605fa0e90e.zip
clean up snippets to follow WC standards
Diffstat (limited to 'snippets/kudos-currency.php')
-rw-r--r--snippets/kudos-currency.php48
1 files changed, 36 insertions, 12 deletions
diff --git a/snippets/kudos-currency.php b/snippets/kudos-currency.php
index ac1cac9..c84936d 100644
--- a/snippets/kudos-currency.php
+++ b/snippets/kudos-currency.php
@@ -1,23 +1,47 @@
+<?php
/**
- * This code is in the public domain.
+ * License: Public domain.
*
- * Support for the KUDOS and TESTKUDOS currency. This goes into functions.php
- * https://gist.github.com/woogists/72947b71e48a62f15f5548283d4ed00f#file-wc-add-currency-symbol-php
+ * 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;
+ $currencies['KUDOS'] = __( 'KUDOS', 'woocommerce' );
+ $currencies['TESTKUDOS'] = __( 'TESTKUDOS', 'woocommerce' );
+ return $currencies;
}
-add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);
+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;
+ switch ( $currency ) {
+ case 'KUDOS':
+ $currency_symbol = 'ク';
+ break;
+ case 'TESTKUDOS':
+ $currency_symbol = 'テ';
+ break;
+ }
+ return $currency_symbol;
}