Skip to content

Commit b7ef201

Browse files
authored
fix: backend currency formatting (#10825)
1 parent 0c0e9d6 commit b7ef201

File tree

4 files changed

+5
-412
lines changed

4 files changed

+5
-412
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+
fix: formatting of currencies in the backend will always honor the merchant's settings, rather than the currency locale.

includes/multi-currency/BackendCurrencies.php

Lines changed: 0 additions & 182 deletions
This file was deleted.

includes/multi-currency/MultiCurrency.php

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@ class MultiCurrency {
9494
*/
9595
protected $frontend_currencies;
9696

97-
/**
98-
* BackendCurrencies instance.
99-
*
100-
* @var BackendCurrencies
101-
*/
102-
protected $backend_currencies;
103-
10497
/**
10598
* StorefrontIntegration instance.
10699
*
@@ -225,7 +218,6 @@ public function init_hooks() {
225218
add_filter( 'woocommerce_get_settings_pages', [ $this, 'init_settings_pages' ] );
226219
// Enqueue the scripts after the main WC_Payments_Admin does.
227220
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ], 20 );
228-
add_action( 'admin_head', [ $this, 'set_client_format_and_rounding_precision' ] );
229221
}
230222

231223
add_action( 'init', [ $this, 'init' ] );
@@ -294,15 +286,13 @@ public function init() {
294286

295287
$this->frontend_prices = new FrontendPrices( $this, $this->compatibility );
296288
$this->frontend_currencies = new FrontendCurrencies( $this, $this->localization_service, $this->utils, $this->compatibility );
297-
$this->backend_currencies = new BackendCurrencies( $this, $this->localization_service );
298289
$this->tracking = new Tracking( $this );
299290

300291
// Init all of the hooks.
301292
$admin_notices->init_hooks();
302293
$user_settings->init_hooks();
303294
$this->frontend_prices->init_hooks();
304295
$this->frontend_currencies->init_hooks();
305-
$this->backend_currencies->init_hooks();
306296
$this->tracking->init_hooks();
307297

308298
add_action( 'woocommerce_order_refunded', [ $this, 'add_order_meta_on_refund' ], 50, 2 );
@@ -1100,37 +1090,6 @@ public function update_settings( $params ) {
11001090
}
11011091
}
11021092

1103-
/**
1104-
* Apply client order currency format and reduces the rounding precision to 2.
1105-
*
1106-
* @return void
1107-
*/
1108-
public function set_client_format_and_rounding_precision() {
1109-
$screen = get_current_screen();
1110-
if ( in_array( $screen->id, [ 'shop_order', 'woocommerce_page_wc-orders' ], true ) ) :
1111-
$order = wc_get_order();
1112-
if ( ! $order ) {
1113-
return;
1114-
}
1115-
$currency = $order->get_currency();
1116-
$currency_format_num_decimals = $this->backend_currencies->get_price_decimals( $currency );
1117-
$currency_format_decimal_sep = $this->backend_currencies->get_price_decimal_separator( $currency );
1118-
$currency_format_thousand_sep = $this->backend_currencies->get_price_thousand_separator( $currency );
1119-
$currency_format = str_replace( [ '%1$s', '%2$s', ' ' ], [ '%s', '%v', ' ' ], $this->backend_currencies->get_woocommerce_price_format( $currency ) );
1120-
1121-
$rounding_precision = wc_get_price_decimals() ?? wc_get_rounding_precision();
1122-
?>
1123-
<script>
1124-
woocommerce_admin_meta_boxes.currency_format_num_decimals = <?php echo (int) $currency_format_num_decimals; ?>;
1125-
woocommerce_admin_meta_boxes.currency_format_decimal_sep = '<?php echo esc_attr( $currency_format_decimal_sep ); ?>';
1126-
woocommerce_admin_meta_boxes.currency_format_thousand_sep = '<?php echo esc_attr( $currency_format_thousand_sep ); ?>';
1127-
woocommerce_admin_meta_boxes.currency_format = '<?php echo esc_attr( $currency_format ); ?>';
1128-
woocommerce_admin_meta_boxes.rounding_precision = <?php echo (int) $rounding_precision; ?>;
1129-
</script>
1130-
<?php
1131-
endif;
1132-
}
1133-
11341093
/**
11351094
* Load script with all required dependencies.
11361095
*
@@ -1370,21 +1329,7 @@ public function adjust_amount_for_selected_currency( $amount, $apply_charm_prici
13701329
* @return string The formatted amount.
13711330
*/
13721331
public function get_backend_formatted_wc_price( float $amount, array $args = [] ): string {
1373-
// Return early if MC isn't enabled or merchant has a single currency.
1374-
if ( ! self::has_additional_currencies_enabled() || ! WC_Payments_Features::is_customer_multi_currency_enabled() ) {
1375-
return wc_price( $amount, $args );
1376-
}
1377-
1378-
$has_filter = has_filter( 'wc_price_args', [ $this->backend_currencies, 'build_wc_price_args' ] );
1379-
if ( false !== $has_filter ) {
1380-
return wc_price( $amount, $args );
1381-
}
1382-
1383-
add_filter( 'wc_price_args', [ $this->backend_currencies, 'build_wc_price_args' ], 50 );
1384-
$price = wc_price( $amount, $args );
1385-
remove_filter( 'wc_price_args', [ $this->backend_currencies, 'build_wc_price_args' ], 50 );
1386-
1387-
return $price;
1332+
return wc_price( $amount, $args );
13881333
}
13891334

13901335
/**

0 commit comments

Comments
 (0)