Skip to content

Commit f6dd0c6

Browse files
authored
Do not change shipping costs structure when applying multi-currency presentation (#10778)
1 parent 4b084af commit f6dd0c6

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Keep the shipping costs structure intact when applying multi-currency adjustments.

includes/multi-currency/FrontendPrices.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,24 @@ public function add_exchange_rate_to_variation_prices_hash( $prices_hash ) {
275275
* @return array Shipping rate args with converted cost.
276276
*/
277277
public function convert_shipping_method_rate_cost( $args ) {
278-
$cost = is_array( $args['cost'] ) ? array_sum( $args['cost'] ) : $args['cost'];
279-
$args = wp_parse_args(
280-
[
281-
'cost' => $this->multi_currency->get_price( $cost, 'shipping' ),
282-
],
283-
$args
284-
);
278+
if ( isset( $args['cost'] ) ) {
279+
/**
280+
* We need to keep the `cost` structure intact when applying
281+
* multi-currency conversions, because downstream it is important
282+
* for WooCommerce to keep the taxes flow consistent.
283+
*/
284+
if ( is_array( $args['cost'] ) ) {
285+
$args['cost'] = array_map(
286+
function ( $cost ) {
287+
return $this->multi_currency->get_price( $cost, 'shipping' );
288+
},
289+
$args['cost']
290+
);
291+
} else {
292+
$args['cost'] = $this->multi_currency->get_price( $args['cost'], 'shipping' );
293+
}
294+
}
295+
285296
return $args;
286297
}
287298

tests/unit/multi-currency/test-class-frontend-prices.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,23 @@ function () {
233233
}
234234

235235
public function test_convert_shipping_method_rate_cost_for_array_cost() {
236+
$matcher = $this->exactly( 2 );
236237
$this->mock_multi_currency
237-
->expects( $this->once() )
238+
->expects( $matcher )
238239
->method( 'get_price' )
239-
->with( '11' )
240-
->willReturn( 25.0 );
240+
->willReturnCallback(
241+
function ( $price ) use ( $matcher ) {
242+
switch ( $matcher->getInvocationCount() ) {
243+
case 1:
244+
$this->assertEquals( 10.0, $price );
245+
break;
246+
case 2:
247+
$this->assertEquals( 1.0, $price );
248+
break;
249+
}
250+
return $price;
251+
}
252+
);
241253

242254
add_filter( 'wc_tax_enabled', '__return_true' );
243255
add_filter(
@@ -272,8 +284,8 @@ function () {
272284
$shipping_rate = $shipping_method->rates[1];
273285

274286
// Cost gets converted and taxes properly calculated based on it.
275-
$this->assertSame( '25.00', $shipping_rate->cost );
276-
$this->assertSame( 2.5, $shipping_rate->taxes[1] );
287+
$this->assertSame( '11.00', $shipping_rate->cost );
288+
$this->assertSame( 1.1, $shipping_rate->taxes[1] );
277289
}
278290

279291
public function test_get_coupon_amount_returns_empty_amount() {

0 commit comments

Comments
 (0)