thank you! ill be checking this one out!
@gzoo encountered a couple issues:
  1. the fiat-price is dropping trailing zeros. for example, 100 will appear as 1
  2. enabling the two bottom filters 'woocommerce_cart_item_price' and 'woocommerce_cart_item_subtotal' break the cart. appears to relate to the $total = floatval line
i'm running: wordpress 6.0.2 woocommerce 7.0.0 btcpay for woocommerce v2 1.1.1 storefront theme by woocommerce
reply
Hi tanaris! thanks for your feedback :)
  1. this is because in my woocommerce I have configured two decimals in the price and in the function woo_product_price_2sats I format the price in $product_p_formated with rtrim($total, ".0"); to avoid having zeros that I don't need. You can solve it in a very simple way, either adding two decimals in the woocommerce price settings (woocommerce>settings) or commenting that line of code and in the fiat price print print "<span class='fiat-price'>&nbsp;{$product_p_formated} €</span>"; replace $product_p_formated with $total.
function woo_product_price_2sats() { global $woo_currency; $all_meta_data = get_post_meta(get_the_ID()); $total=$all_meta_data['_regular_price'][0]; $price_oracle_url = "https://blockchain.info/tobtc?currency=$woo_currency&value=$total"; $ch = curl_init($price_oracle_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = number_format(ltrim(curl_exec($ch), "0.")); $product_p_formated=rtrim($total, ".0"); curl_close($ch); print "<span class='btc-price'>{$data} Sats&nbsp;</span>"; print "<span class='fiat-price'>&nbsp;{$product_p_formated} €</span>"; }
  1. Yes, I've had those problems too (that's why they appear disabled), it's because woocommerce doesn't have a filter to differentiate between the cart page and the minicart and that breaks it, however I already have a way to do it by digging in the woocommerce template files, I haven't had time to develop it yet, but it's the starting point.
reply
good deal gzoo. appreciate you taking the time to respond and layout a solution here. ill look forward to your revision with cart/minicart fixes. thanks again!
reply