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"));
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