Hello. Can you please advise on a method to obtain the exchange rate of the local currency relative to the base currency on the frontend? For instance, I have a discount value in the base currency stored in the product’s meta field. I need to convert this value to the local currency, considering the current exchange rate, rounding, and any fees associated with the exchange (which are configured in the marketplace).
I can be more specific. This value should precisely correspond to the presentmentCurrencyRate used in the discount function extension for Cart Input:
/** The input object for the function. */
export type Input = {
__typename?: 'Input';
/** The cart. */
cart: Cart;
/** The discount node executing the function. */
discountNode: DiscountNode;
/** The localization of the Function execution context. */
localization: Localization;
/** The conversion rate between the shop's currency and the currency of the cart. */
presentmentCurrencyRate: Scalars['Decimal'];
/** Information about the shop. */
shop: Shop;
};
Does the native way to support multiple currencies and languages in Shopify themes not fit your use case? If not, one option would be to make a call to a currency exchange API and once you have the exchange rate, you can convert the discount value from the base currency to the local currency. You can write a JavaScript function that takes the base discount value, exchange rate, and fees as inputs and returns the converted value. This function can be called on the frontend wherever the converted discount value needs to be displayed.
Don’t use the JavaScript currency reference. There will be large differences in money values between Shopify’s built in multi-currency values outputted in Liquid based on the Shopify Markets rules compared to the currency.js conversion rates that are updated hourly.
I’m note sure sure that JS solution is valid.
Do you have any idea to pass via liquid as element param?
Create a dummy product and hide it from your store. (you may need an app or do some theme dev to hide it well)
Set the dummy product compare_at_price to $1, or 1 unit of your store default currency. (I use compare_at_price here so that i can set the price of the product to $0 just in case someone manages to add it to cart).
in liquid you can do something like this:
This is GENIUS, thank you so much for posting your solution! This has been a big issue for me specifically when it comes to allowing merchants to input numbers (such as for a cart threshold value) but that value is never converted to the local currency. This will solve that issue for me, so I can get relative rates.