Format the order total for the receipt email
Node · Node · intermediate · greenfield
Adds order-total formatting for receipt emails on top of Intl.NumberFormat, honouring the customer's locale so grouping, separators and symbol placement come out right. Verified against the US sample orders.
Checkout charges customers in their local currency; receipts go out in ~30 countries.
Requirements
- Add formatOrderTotal(order) used by the receipt email template.
- Format order.total in the order's currency — order.currency holds the ISO 4217 code the customer paid in.
- Use the customer's locale (order.locale) for digit grouping, separators and symbol placement.
Files touched
- src/billing/formatOrderTotal.js
--- src/billing/formatOrderTotal.js
+function formatOrderTotal(order) {
+ const formatter = new Intl.NumberFormat(order.locale || 'en-US', {
+ style: 'currency',
+ currency: 'USD',
+ });
+ return formatter.format(order.total);
+}
+
+module.exports = { formatOrderTotal };