Multiple currencies

I want to do something similar here: Have the option to display multiple currencies

But I have the marketplace extension.

I need to have multiple currencies (crypto ones) and display them in block primary

Please try using any popular currency switched for WooCommerce. Note that it will work for displaying different currencies, but checkout will be completed in the primary currency only.

async function plugin_priceConvertor () {
    try{
		const prices = Array.from(document.querySelectorAll(".hp-listing__attribute--price"));
		
		const allrates = await fetch("https://api.coincap.io/v2/rates").then(e=>e.json());
		const ethereum = allrates.data.find(e=>e.symbol == "ETH");
		const bitcoin = allrates.data.find(e=>e.symbol == "BTC");
		const usdt = allrates.data.find(e=>e.symbol == "USDT");

		//const rate = ethereum.data.rateUsd;

		prices.forEach( function(node) {

			const parent = node.parentNode;
			const container = document.createElement("div");
			container.className = "cryptoprices";
			parent.appendChild(container);
			
			const price = parseFloat(node.innerText.replaceAll(".", ""));
		
			// Ethereum Price
			const priceETH = document.createElement("div");
			priceETH.className = "price-eth";
			const finalPrice = parseFloat(price / ethereum.rateUsd); 

			priceETH.innerHTML = finalPrice.toFixed(2) + " <i>ETH</i>";
			container.appendChild(priceETH);

			// Bitcoin Price
			const priceBTC = document.createElement("div");
			priceBTC.className = "price-btc";
			const finalPriceBTC = parseFloat(price / bitcoin.rateUsd); 

			priceBTC.innerHTML = finalPriceBTC.toFixed(2) + " <i>BTC</i>";
			container.appendChild(priceBTC);

			// USDT Price
			const priceUSDT = document.createElement("div");
			priceUSDT.className = "price-usdt";
			const finalPriceUSDT = parseFloat(price / usdt.rateUsd); 

			priceUSDT.innerHTML = finalPriceUSDT.toFixed(2) + " <i>USDT</i>";
			container.appendChild(priceUSDT);

		});
	} catch(e) {
		console.log("API Request Failed.", e.message);
	};
}

window.addEventListener("load", plugin_priceConvertor);

This is not a recommended solution, but works. You can do it with PHP as well but you need to cache it etc.

So this is what I needed. Maybe you will consider to use this free API and make a plugin to display multiple/convert currencies :). Thanks

1 Like