Selectively display WooCommerce product prices in any cryptocurrency

This snippet for WooCommerce shows how to selectively display product prices in different cryptocurrencies instead of the default store currency.

1) Visit any WooCommerce product you want the price to be displayed as a cryptocurrency. Open the screen options and check to make sure “custom fields” are shown in the editor.


2) To change the displayed currency of a specific product, add a custom field called “mcc_product_currency” to the product. Set the value of the custom field to whatever cryptocurrency symbol MyCryptoCheckout supports such as: BTC, ETH, LTC. For a full list of currencies please visit the supported coins page.


3) Add the code snippet below to your theme’s functions.php file or into a custom plugin.

	@brief		Show WooCommerce product prices in various cryptocurrencies.
	@details	Add a custom field called "mcc_product_currency" to the product. Set the custom field value to the symbol (BTC, ETH, etc) of the currency you wish the product price in.
	@since		2018-07-16 11:55:06
function mcc_woocommerce_get_price_html( $text, $product )
    // Is MCC installed?
    if ( ! function_exists( 'mycryptocheckout' ) )
        return $text;

    // Does the product has the correct custom field?
    $currency_id = $product->get_meta( 'mcc_product_currency' );
    if ( ! $currency_id )
        return $text;

    // Retrieve all of our currencies.
    $currencies = MyCryptoCheckout()->currencies();
    $currency = $currencies->get( $currency_id );
    // Is this currency known?
    if ( ! $currency )
        return $text;

    $new_price = $currency->convert( get_woocommerce_currency(), $product->get_price() );
    return $new_price  . ' ' . $currency_id;
add_filter( 'woocommerce_get_price_html', 'mcc_woocommerce_get_price_html', 100, 2 );


4) Product prices will now be displayed in the cryptocurrency you chose!