hi guys! how are you? I have a question for worpress developers. What would be the easiest way to convert the currency I have set in my woocommerce shop to btc? Right now I have my products with prices set in € but I would like to show the equivalent in btc/sats. I was thinking in a snippet in function.php or something. do any of you already have a solution for this?

Im using btcpayserver connected to my node, but i dont find any setting to do that

I am grateful for any help or guidance you can give me.


It's been many moons since I wrote some PHP, but let's give this a go:


1function fiat_to_btc($price, $currency_code) { 2 $price_oracle_url = "https://blockchain.info/tobtc?currency=$currency_code&value=$price"; 3 4 $ch = curl_init($price_oracle_url); 5 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 6 curl_setopt($ch, CURLOPT_HEADER, 0); 7 $data = curl_exec($ch); 8 curl_close($ch); 9 10 return $data; 11} 12 13##Example 14print(fiat_to_btc(99.99, "EUR"));

Thanks man it really helps!! I have adapted the function to work in the front end of wordpress, just add this to the function.php file of your theme.

In case anyone wants to use/understand it: What the function does is to take the regular price of the woocommerce product, store it in the variable $product_p and then pass the price acquired through the get of $price_oracle_url. after that the price of the product converted to btc with an updated exchange rate appears in the front end through add_action and inside a html span tag with the css class btc-price, so you can play with a custom css.

1function woocommerce_regular_price_tobtc(){ 2 $all_meta_data = get_post_meta(get_the_ID()); 3 $product_p=$all_meta_data['_regular_price'][0]; 4 $price_oracle_url = "https://blockchain.info/tobtc?currency=eur&value=$product_p"; 5 $ch = curl_init($price_oracle_url); 6 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 7 curl_setopt($ch, CURLOPT_HEADER, 0); 8 $data = curl_exec($ch); 9 curl_close($ch); 10 print "<span class='btc-price'>{$data}₿</span>"; 11 12} 13 14add_action('woocommerce_before_add_to_cart_form', 'woocommerce_regular_price_tobtc'); 15

Glad you got it working!

Better can answer @d11n about this.

it would be amazing if @d11n had an answer to this. Tanks :)