@@ -1169,6 +1169,37 @@ public function get_normalized_shipping_rates() {
1169
1169
return $ shipping_rates ;
1170
1170
}
1171
1171
1172
+ /**
1173
+ * Convert the product price to the base currency using WooCommerce Payments Multi-Currency.
1174
+ *
1175
+ * @param float $total_price Total product price.
1176
+ * @return float Converted price in base currency.
1177
+ */
1178
+ private function maybe_convert_to_base_currency ( $ total_price ) {
1179
+ if ( ! class_exists ( 'WCPay\MultiCurrency\MultiCurrency ' ) ) {
1180
+ return $ total_price ;
1181
+ }
1182
+
1183
+ $ multi_currency = WCPay \MultiCurrency \MultiCurrency::instance ();
1184
+ $ selected_currency = $ multi_currency ->get_selected_currency ();
1185
+ $ base_currency = $ multi_currency ->get_default_currency ();
1186
+
1187
+ // If the selected currency is the same as the base currency, return the original price.
1188
+ if ( $ selected_currency ->get_code () === $ base_currency ->get_code () ) {
1189
+ return $ total_price ;
1190
+ }
1191
+
1192
+ try {
1193
+ $ converted_price = $ multi_currency ->get_raw_conversion ( (float ) $ total_price , $ base_currency ->get_code (), $ selected_currency ->get_code () );
1194
+ } catch ( Exception $ e ) {
1195
+ // Log the error for better debugging.
1196
+ wc_get_logger ()->error ( $ e ->getMessage (), array ( 'source ' => 'woocommerce-table-rate-shipping ' ) );
1197
+ return $ total_price ;
1198
+ }
1199
+
1200
+ return $ converted_price ;
1201
+ }
1202
+
1172
1203
/**
1173
1204
* Retrieve the product price from a line item.
1174
1205
*
@@ -1180,7 +1211,7 @@ public function get_normalized_shipping_rates() {
1180
1211
public function get_product_price ( $ _product , $ qty = 1 , $ item = array () ) {
1181
1212
1182
1213
/**
1183
- * Filter to let third party use the product price with discounts or without discounts to calculate Min-Max conditions.
1214
+ * Filter to let third party use the product price with discounts or without discounts to calculate Min-Max conditions.
1184
1215
*
1185
1216
* @param boolean minmax_after_discount option value.
1186
1217
* @param array Cart item.
@@ -1190,6 +1221,9 @@ public function get_product_price( $_product, $qty = 1, $item = array() ) {
1190
1221
if ( apply_filters ( 'woocommerce_table_rate_compare_price_limits_after_discounts ' , wc_string_to_bool ( $ this ->minmax_after_discount ), $ item ) && isset ( $ item ['line_total ' ] ) ) {
1191
1222
$ row_base_price = $ item ['line_total ' ] + ( wc_string_to_bool ( $ this ->minmax_with_tax ) && isset ( $ item ['line_tax ' ] ) ? $ item ['line_tax ' ] : 0 );
1192
1223
1224
+ // Convert to base currency if needed.
1225
+ $ row_base_price = $ this ->maybe_convert_to_base_currency ( $ row_base_price );
1226
+
1193
1227
/**
1194
1228
* Filter to let third party modify the row base price.
1195
1229
*
@@ -1203,6 +1237,9 @@ public function get_product_price( $_product, $qty = 1, $item = array() ) {
1203
1237
} elseif ( isset ( $ item ['line_subtotal ' ] ) ) {
1204
1238
$ row_base_price = $ item ['line_subtotal ' ] + ( wc_string_to_bool ( $ this ->minmax_with_tax ) && isset ( $ item ['line_subtotal_tax ' ] ) ? $ item ['line_subtotal_tax ' ] : 0 );
1205
1239
1240
+ // Convert to base currency if needed.
1241
+ $ row_base_price = $ this ->maybe_convert_to_base_currency ( $ row_base_price );
1242
+
1206
1243
/**
1207
1244
* Filter to let third party modify the row base price.
1208
1245
*
@@ -1215,13 +1252,17 @@ public function get_product_price( $_product, $qty = 1, $item = array() ) {
1215
1252
return apply_filters ( 'woocommerce_table_rate_package_row_base_price ' , $ row_base_price , $ _product , $ qty );
1216
1253
}
1217
1254
1255
+ // Default price calculation.
1218
1256
$ row_base_price = $ _product ->get_price () * $ qty ;
1219
1257
1220
- // From Issue #134 : Adding a compatibility product price for Measurement Price Calculator plugin by SkyVerge.
1258
+ // From Issue #134: Adding a compatibility product price for Measurement Price Calculator plugin by SkyVerge.
1221
1259
if ( class_exists ( 'WC_Measurement_Price_Calculator_Loader ' ) && isset ( $ item ['pricing_item_meta_data ' ]['_price ' ] ) ) {
1222
1260
$ row_base_price = $ item ['pricing_item_meta_data ' ]['_price ' ] * $ qty ;
1223
1261
}
1224
1262
1263
+ // Convert to base currency if needed.
1264
+ $ row_base_price = $ this ->maybe_convert_to_base_currency ( $ row_base_price );
1265
+
1225
1266
/**
1226
1267
* Filter to let third party modify the row base price.
1227
1268
*
0 commit comments