Learnpress: Adding Custom Currency


Learnpress is a popular LMS plugin for WordPress that offers great options for creating online courses. By default, LearnPress comes with many currency options. However, if you wish to add another currency, the process is very straightforward.

Custom code for adding custom currency

Copy the code below and paste it in  functions.php file (child theme) and swap out the currency code and symbol with your own. The reason for advising adding the code in a Child theme is that if you do in the main theme, te code will be wiped out in the next update of theme.

/**
* Add new currency
*
* @param $currencies
*
* @return mixed
*/

add_filter('learn_press_get_payment_currencies', 'my_cbf_learn_press_get_payment_currencies', 10, 1 ); // for LearnPress 2
add_filter('learn-press/currencies', 'my_cbf_learn_press_get_payment_currencies', 10, 1 ); // for LearnPress 3
function my_cbf_learn_press_get_payment_currencies( $currencies ){
$currency_new = 'Code'; # Currency Code
$currency_name = __('Currency name', 'learnpress'); # Full name of Currency
if( !isset($currencies[$currency_new]) || ( isset($currencies[$currency_new]) && $currencies[$currency_new] !== $currency_name ) ) {
$currencies[$currency_new] = $currency_name;
}
return $currencies;
}
add_filter( 'learn_press_currency_symbol', 'my_cbf_learn_press_currency_symbol', 10, 2 );
function my_cbf_learn_press_currency_symbol( $currency_symbol, $currency ) {
$currency_new = 'Code'; # Currency Code
if( $currency == $currency_new ) {
$currency_symbol = 'Symbol'; # Symbol of currency
}
return $currency_symbol;
}

After saving changes, it should be available from your LearnPress / Settings / General / Currency

Video on Adding Custom Currency