Skip to content

Commit 3d7300f

Browse files
author
Woo
committed
Updates to 3.3.0
1 parent 1f2c306 commit 3d7300f

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
*** Table Rate Shipping Changelog ***
22

3+
2024-07-16 - version 3.3.0
4+
* Add - Compatibility with WooPayments Multi-currency tool.
5+
36
2024-07-02 - version 3.2.2
47
* Tweak - WordPress 6.6 and WooCommerce 9.0 compatibility.
58

includes/class-wc-shipping-table-rate.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,37 @@ public function get_normalized_shipping_rates() {
11691169
return $shipping_rates;
11701170
}
11711171

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+
11721203
/**
11731204
* Retrieve the product price from a line item.
11741205
*
@@ -1180,7 +1211,7 @@ public function get_normalized_shipping_rates() {
11801211
public function get_product_price( $_product, $qty = 1, $item = array() ) {
11811212

11821213
/**
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.
11841215
*
11851216
* @param boolean minmax_after_discount option value.
11861217
* @param array Cart item.
@@ -1190,6 +1221,9 @@ public function get_product_price( $_product, $qty = 1, $item = array() ) {
11901221
if ( apply_filters( 'woocommerce_table_rate_compare_price_limits_after_discounts', wc_string_to_bool( $this->minmax_after_discount ), $item ) && isset( $item['line_total'] ) ) {
11911222
$row_base_price = $item['line_total'] + ( wc_string_to_bool( $this->minmax_with_tax ) && isset( $item['line_tax'] ) ? $item['line_tax'] : 0 );
11921223

1224+
// Convert to base currency if needed.
1225+
$row_base_price = $this->maybe_convert_to_base_currency( $row_base_price );
1226+
11931227
/**
11941228
* Filter to let third party modify the row base price.
11951229
*
@@ -1203,6 +1237,9 @@ public function get_product_price( $_product, $qty = 1, $item = array() ) {
12031237
} elseif ( isset( $item['line_subtotal'] ) ) {
12041238
$row_base_price = $item['line_subtotal'] + ( wc_string_to_bool( $this->minmax_with_tax ) && isset( $item['line_subtotal_tax'] ) ? $item['line_subtotal_tax'] : 0 );
12051239

1240+
// Convert to base currency if needed.
1241+
$row_base_price = $this->maybe_convert_to_base_currency( $row_base_price );
1242+
12061243
/**
12071244
* Filter to let third party modify the row base price.
12081245
*
@@ -1215,13 +1252,17 @@ public function get_product_price( $_product, $qty = 1, $item = array() ) {
12151252
return apply_filters( 'woocommerce_table_rate_package_row_base_price', $row_base_price, $_product, $qty );
12161253
}
12171254

1255+
// Default price calculation.
12181256
$row_base_price = $_product->get_price() * $qty;
12191257

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.
12211259
if ( class_exists( 'WC_Measurement_Price_Calculator_Loader' ) && isset( $item['pricing_item_meta_data']['_price'] ) ) {
12221260
$row_base_price = $item['pricing_item_meta_data']['_price'] * $qty;
12231261
}
12241262

1263+
// Convert to base currency if needed.
1264+
$row_base_price = $this->maybe_convert_to_base_currency( $row_base_price );
1265+
12251266
/**
12261267
* Filter to let third party modify the row base price.
12271268
*

languages/woocommerce-table-rate-shipping.pot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# This file is distributed under the GNU General Public License v3.0.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: WooCommerce Table Rate Shipping 3.2.2\n"
5+
"Project-Id-Version: WooCommerce Table Rate Shipping 3.3.0\n"
66
"Report-Msgid-Bugs-To: "
77
"https://wordpress.org/support/plugin/woocommerce-table-rate-shipping\n"
8-
"POT-Creation-Date: 2024-07-02 11:06:58+00:00\n"
8+
"POT-Creation-Date: 2024-07-16 22:56:05+00:00\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=utf-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
@@ -228,7 +228,7 @@ msgstr ""
228228
msgid "Class Priorities"
229229
msgstr ""
230230

231-
#: includes/class-wc-shipping-table-rate.php:1386
231+
#: includes/class-wc-shipping-table-rate.php:1427
232232
#. translators: %s: message
233233
msgid ""
234234
"You have overlapping shipping rates defined, which may offer multiple "

woocommerce-table-rate-shipping.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: WooCommerce Table Rate Shipping
44
* Plugin URI: https://woocommerce.com/products/table-rate-shipping/
55
* Description: Table rate shipping lets you define rates depending on location vs shipping class, price, weight, or item count.
6-
* Version: 3.2.2
6+
* Version: 3.3.0
77
* Author: WooCommerce
88
* Author URI: https://woocommerce.com/
99
* Text Domain: woocommerce-table-rate-shipping
@@ -13,8 +13,8 @@
1313
* Domain Path: /languages
1414
* Requires Plugins: woocommerce
1515
* Tested up to: 6.6
16-
* WC tested up to: 9.0
17-
* WC requires at least: 8.8
16+
* WC tested up to: 9.1
17+
* WC requires at least: 8.9
1818
*
1919
* Woo: 18718:3034ed8aff427b0f635fe4c86bbf008a
2020
*
@@ -26,7 +26,7 @@
2626
}
2727

2828
if ( ! defined( 'TABLE_RATE_SHIPPING_VERSION' ) ) {
29-
define( 'TABLE_RATE_SHIPPING_VERSION', '3.2.2' ); // WRCS: DEFINED_VERSION.
29+
define( 'TABLE_RATE_SHIPPING_VERSION', '3.3.0' ); // WRCS: DEFINED_VERSION.
3030
}
3131

3232
if ( ! defined( 'TABLE_RATE_SHIPPING_DEBUG' ) ) {

0 commit comments

Comments
 (0)