Skip to content

Commit

Permalink
Add-ons: Use integer values for currency in useAddOnDisplayCost (#81461)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirbrillig authored Sep 7, 2023
1 parent af15567 commit 62187e0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client/my-sites/add-ons/hooks/use-add-on-display-cost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const useAddOnDisplayCost = ( productSlug: string, quantity?: number ) => {

return useSelector( ( state ) => {
const product = getProductBySlug( state, productSlug );
let cost = product?.cost;
let cost = product?.cost_smallest_unit;
const currencyCode = getProductCurrencyCode( state, productSlug );

if ( ! ( cost && currencyCode ) ) {
Expand All @@ -25,12 +25,13 @@ const useAddOnDisplayCost = ( productSlug: string, quantity?: number ) => {
} );

if ( priceTier ) {
cost = priceTier?.maximum_price / 100;
cost = priceTier?.maximum_price;
}

if ( product?.product_term === 'month' ) {
const formattedCost = formatCurrency( cost, currencyCode, {
stripZeros: true,
isSmallestUnit: true,
} );
return translate( '%(formattedCost)s/month, billed monthly', {
/* Translators: $formattedCost: monthly price formatted with currency */
Expand All @@ -42,6 +43,7 @@ const useAddOnDisplayCost = ( productSlug: string, quantity?: number ) => {

const monthlyCost = formatCurrency( cost / 12, currencyCode, {
stripZeros: true,
isSmallestUnit: true,
} );

return translate( '%(monthlyCost)s/month, billed yearly', {
Expand Down

0 comments on commit 62187e0

Please sign in to comment.