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:
function fiat_to_btc($price, $currency_code) { $price_oracle_url = "https://blockchain.info/tobtc?currency=$currency_code&value=$price"; $ch = curl_init($price_oracle_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); return $data; } ##Example print(fiat_to_btc(99.99, "EUR"));
reply
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.
function woocommerce_regular_price_tobtc(){ $all_meta_data = get_post_meta(get_the_ID()); $product_p=$all_meta_data['_regular_price'][0]; $price_oracle_url = "https://blockchain.info/tobtc?currency=eur&value=$product_p"; $ch = curl_init($price_oracle_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); print "<span class='btc-price'>{$data}₿</span>"; } add_action('woocommerce_before_add_to_cart_form', 'woocommerce_regular_price_tobtc');
reply
Glad you got it working!
reply
Better can answer @d11n about this.
reply
it would be amazing if @d11n had an answer to this. Tanks :)
reply