Last active
June 11, 2021 12:25
-
-
Save malsubrata/eef889c8bbda33fa32f9252ae4691f11 to your computer and use it in GitHub Desktop.
Aelia Currency Switcher for WooCommerce Support (Multi currency)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('woo_wallet_amount', 'woo_wallet_amount_callback', 10, 2); | |
add_filter('woo_wallet_current_balance', 'woo_wallet_current_balance_callback', 10, 2); | |
if (!function_exists('woo_wallet_current_balance_callback')) { | |
function woo_wallet_current_balance_callback($balance, $user_id) { | |
$credit_amount = $debit_amount = 0; | |
$credit_array = get_wallet_transactions(array('user_id' => $user_id, 'where' => array(array('key' => 'type', 'value' => 'credit')), 'nocache' => true)); | |
foreach ($credit_array as $credit) { | |
$credit_amount += get_terawallet_converted_amount($credit->amount, $credit->currency); | |
} | |
$debit_array = get_wallet_transactions(array('user_id' => $user_id, 'where' => array(array('key' => 'type', 'value' => 'debit')), 'nocache' => true)); | |
foreach ($debit_array as $debit) { | |
$debit_amount += get_terawallet_converted_amount($debit->amount, $debit->currency); | |
} | |
return $credit_amount - $debit_amount; | |
} | |
} | |
function woo_wallet_amount_callback($amount, $currency) { | |
return get_terawallet_converted_amount($amount, $currency); | |
} | |
if (!function_exists('get_terawallet_converted_amount')) { | |
function get_terawallet_converted_amount($amount = 0, $currency = '') { | |
if (class_exists('WC_Aelia_CurrencySwitcher')) { | |
if (!$currency) { | |
$currency = Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher::settings()->base_currency(); | |
} | |
$site_currency = get_woocommerce_currency(); | |
$WC_Aelia_CurrencySwitcher = Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher::instance(); | |
$amount = $WC_Aelia_CurrencySwitcher->convert($amount, $currency, $site_currency); | |
} | |
return $amount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment