Special Offer: Get All 151 Premium WordPress Themes for Just $99.99 $59.99 Purchase Now Learn more

How to Display Bitcoin Price in WooCommerce Store

How to Display Bitcoin Price in WooCommerce Store

In case you accept Bitcoins in your WooCommerce online store (you can check how it can be configured HERE), you may want to display the Bitcoin price next to the original price in currency just like the screenshot above.

The above will require a small code change, here are all of the necessary step:

1. Predefine the WooCommerce price template

1.1. Download WooCommerce plugin zip file then unzip it on your computer

1.2. Navigate to YourComputer\ExtractedFolder\woocommerce\templates\single-product and copy the price.php

1.3. Copy the above file to YourWordPressThemeFolder\woocommerce\single-product\price.php

In case some of the above folders does Not exist, you will have to create them.

2. Update WooCommerce price template

Once you have the WooCommece price template added at your theme, you can add changes to it. When site is loaded and single product page is opened in browers, the price will be loaded from price template from your theme folder instead of price template from the plugin.

2.1. Open YourWordPressThemeFolder\woocommerce\single-product\price.php

and insert the following code below ‘<?php echo $product->get_price_html(); ?>’:

<?php
$productPrice = $product->get_price();
if ( $productPrice != ‘0’ ) {

$url = “https://bitpay.com/api/rates”;
$json = file_get_contents($url);
$data = json_decode($json, TRUE);

foreach($data as $row) {
if ($row[‘code’] == ‘USD’) {

$rate = $row[‘rate’];
$bitcoin_price = round( $productPrice / $rate , 8 );

if ($bitcoin_price) {
echo ‘<span class=”btc-price”> / <i class=”fa fa-btc” aria-hidden=”true”></i>’ . $bitcoin_price . ‘ BTC</span>’;
}

break;
}
}
}
?>

2.3. Save changes and upload the updated price template to your server theme folder (at same location yourtheme\woocommerce\single-product\price.php)

One Response to “How to Display Bitcoin Price in WooCommerce Store”

  1. Hi there does this code still work? I’ve been trying to get it to work but without any luck.

    thanks