Last active
June 1, 2022 22:25
-
-
Save ndeet/675a7e099169c5b2c0d57e3ce0f894f7 to your computer and use it in GitHub Desktop.
Output BTC as Sats value for WOOCS (WooCommerce Currency Switcher)
This file contains 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
// Assumption is that you fetch the correct Bitcoin exchange rates for the currency code ($currencyCode) "BTC". | |
// Adjust accordingly in the code below if you use a different one. | |
// On WOOCS settings you can add a custom symbol for "Sats" and display it accordingly. | |
// Use WOOCS currency data manipulation filter to adjust rate and decimals. | |
add_filter('woocs_currency_data_manipulation', 'my_woocs_currency_data_manipulation', 1, 1); | |
function my_woocs_currency_data_manipulation($currencies) | |
{ | |
$currencyCode = 'BTC'; // Adjust this if your Bitcoin currency code is not BTC | |
foreach ($currencies as $key => $value) | |
{ | |
if ($key === $currencyCode) | |
{ | |
// We multiply the Bitcoin exchange rate with 100 million. 1 BTC == 100 000 000 Sats. | |
$currencies[$key]['rate'] = $value['rate'] * 100000000; | |
$currencies[$key]['decimals'] = 0; | |
break; | |
} | |
} | |
return $currencies; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment