Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit bebf90c

Browse files
committed
Fix product price not displaying properly when product is on sale (#3853)
* Use else if in ProductPrice This is because the priceComponent variable should be set depending on some conditions, but multiple of them could be true, so by using else if we only handle the first true case * Update snapshots for jest
1 parent cc5ac3b commit bebf90c

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

assets/js/base/components/product-price/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ const ProductPrice = ( {
126126
}
127127

128128
const isDiscounted = regularPrice && price !== regularPrice;
129-
130129
let priceComponent = (
131130
<span
132131
className={ classNames(
@@ -148,9 +147,7 @@ const ProductPrice = ( {
148147
regularPriceStyle={ regularPriceStyle }
149148
/>
150149
);
151-
}
152-
153-
if ( minPrice !== null && maxPrice !== null ) {
150+
} else if ( minPrice !== null && maxPrice !== null ) {
154151
priceComponent = (
155152
<PriceRange
156153
currency={ currency }
@@ -160,9 +157,7 @@ const ProductPrice = ( {
160157
priceStyle={ priceStyle }
161158
/>
162159
);
163-
}
164-
165-
if ( price !== null ) {
160+
} else if ( price !== null ) {
166161
priceComponent = (
167162
<FormattedMonetaryAmount
168163
className={ classNames(

assets/js/base/components/product-price/test/__snapshots__/index.js.snap

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,25 @@ exports[`ProductPrice should apply the format if one is provided 1`] = `
66
>
77
pre price
88
<span
9-
className="wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-product-price__value"
9+
className="screen-reader-text"
1010
>
11-
£0.50
11+
Previous price:
1212
</span>
13+
<del
14+
className="wc-block-components-product-price__regular"
15+
>
16+
£1.00
17+
</del>
18+
<span
19+
className="screen-reader-text"
20+
>
21+
Discounted price:
22+
</span>
23+
<ins
24+
className="wc-block-components-product-price__value is-discounted"
25+
>
26+
£0.50
27+
</ins>
1328
Test format
1429
</span>
1530
`;
@@ -19,9 +34,24 @@ exports[`ProductPrice should use default price if no format is provided 1`] = `
1934
className="price wc-block-components-product-price"
2035
>
2136
<span
22-
className="wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-product-price__value"
37+
className="screen-reader-text"
2338
>
24-
£0.50
39+
Previous price:
2540
</span>
41+
<del
42+
className="wc-block-components-product-price__regular"
43+
>
44+
£1.00
45+
</del>
46+
<span
47+
className="screen-reader-text"
48+
>
49+
Discounted price:
50+
</span>
51+
<ins
52+
className="wc-block-components-product-price__value is-discounted"
53+
>
54+
£0.50
55+
</ins>
2656
</span>
2757
`;

0 commit comments

Comments
 (0)