Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update priority for Multi-Currency filters for prices and currency #4939

Merged
4 changes: 4 additions & 0 deletions changelog/update-4938-update-multi-currency-filter-priority
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: update

Update priority for Multi-Currency filters for prices and currency to later priority to avoid plugin conflicts.
14 changes: 7 additions & 7 deletions includes/multi-currency/FrontendCurrencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ public function __construct( MultiCurrency $multi_currency, WC_Payments_Localiza

if ( ! is_admin() && ! defined( 'DOING_CRON' ) && ! Utils::is_admin_api_request() ) {
// Currency hooks.
add_filter( 'woocommerce_currency', [ $this, 'get_woocommerce_currency' ], 50 );
add_filter( 'wc_get_price_decimals', [ $this, 'get_price_decimals' ], 50 );
add_filter( 'wc_get_price_decimal_separator', [ $this, 'get_price_decimal_separator' ], 50 );
add_filter( 'wc_get_price_thousand_separator', [ $this, 'get_price_thousand_separator' ], 50 );
add_filter( 'woocommerce_price_format', [ $this, 'get_woocommerce_price_format' ], 50 );
add_filter( 'woocommerce_currency', [ $this, 'get_woocommerce_currency' ], 900 );
add_filter( 'wc_get_price_decimals', [ $this, 'get_price_decimals' ], 900 );
add_filter( 'wc_get_price_decimal_separator', [ $this, 'get_price_decimal_separator' ], 900 );
add_filter( 'wc_get_price_thousand_separator', [ $this, 'get_price_thousand_separator' ], 900 );
add_filter( 'woocommerce_price_format', [ $this, 'get_woocommerce_price_format' ], 900 );
add_action( 'before_woocommerce_pay', [ $this, 'init_order_currency_from_query_vars' ] );
}

add_filter( 'woocommerce_thankyou_order_id', [ $this, 'init_order_currency' ] );
add_action( 'woocommerce_account_view-order_endpoint', [ $this, 'init_order_currency' ], 9 );
add_filter( 'woocommerce_cart_hash', [ $this, 'add_currency_to_cart_hash' ], 50 );
add_filter( 'woocommerce_shipping_method_add_rate_args', [ $this, 'fix_price_decimals_for_shipping_rates' ], 50, 2 );
add_filter( 'woocommerce_cart_hash', [ $this, 'add_currency_to_cart_hash' ], 900 );
add_filter( 'woocommerce_shipping_method_add_rate_args', [ $this, 'fix_price_decimals_for_shipping_rates' ], 900, 2 );
}

/**
Expand Down
30 changes: 15 additions & 15 deletions includes/multi-currency/FrontendPrices.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@ public function __construct( MultiCurrency $multi_currency, Compatibility $compa

if ( ! is_admin() && ! defined( 'DOING_CRON' ) && ! Utils::is_admin_api_request() ) {
// Simple product price hooks.
add_filter( 'woocommerce_product_get_price', [ $this, 'get_product_price_string' ], 50, 2 );
add_filter( 'woocommerce_product_get_regular_price', [ $this, 'get_product_price_string' ], 50, 2 );
add_filter( 'woocommerce_product_get_sale_price', [ $this, 'get_product_price_string' ], 50, 2 );
add_filter( 'woocommerce_product_get_price', [ $this, 'get_product_price_string' ], 900, 2 );
add_filter( 'woocommerce_product_get_regular_price', [ $this, 'get_product_price_string' ], 900, 2 );
add_filter( 'woocommerce_product_get_sale_price', [ $this, 'get_product_price_string' ], 900, 2 );

// Variation price hooks.
add_filter( 'woocommerce_product_variation_get_price', [ $this, 'get_product_price_string' ], 50, 2 );
add_filter( 'woocommerce_product_variation_get_regular_price', [ $this, 'get_product_price_string' ], 50, 2 );
add_filter( 'woocommerce_product_variation_get_sale_price', [ $this, 'get_product_price_string' ], 50, 2 );
add_filter( 'woocommerce_product_variation_get_price', [ $this, 'get_product_price_string' ], 900, 2 );
add_filter( 'woocommerce_product_variation_get_regular_price', [ $this, 'get_product_price_string' ], 900, 2 );
add_filter( 'woocommerce_product_variation_get_sale_price', [ $this, 'get_product_price_string' ], 900, 2 );

// Variation price range hooks.
add_filter( 'woocommerce_variation_prices', [ $this, 'get_variation_price_range' ], 50 );
add_filter( 'woocommerce_get_variation_prices_hash', [ $this, 'add_exchange_rate_to_variation_prices_hash' ], 50 );
add_filter( 'woocommerce_variation_prices', [ $this, 'get_variation_price_range' ], 900 );
add_filter( 'woocommerce_get_variation_prices_hash', [ $this, 'add_exchange_rate_to_variation_prices_hash' ], 900 );

// Shipping methods hooks.
add_action( 'init', [ $this, 'register_free_shipping_filters' ], 50 );
add_filter( 'woocommerce_shipping_method_add_rate_args', [ $this, 'convert_shipping_method_rate_cost' ], 50 );
add_action( 'init', [ $this, 'register_free_shipping_filters' ], 900 );
add_filter( 'woocommerce_shipping_method_add_rate_args', [ $this, 'convert_shipping_method_rate_cost' ], 900 );

// Coupon hooks.
add_filter( 'woocommerce_coupon_get_amount', [ $this, 'get_coupon_amount' ], 50, 2 );
add_filter( 'woocommerce_coupon_get_minimum_amount', [ $this, 'get_coupon_min_max_amount' ], 50 );
add_filter( 'woocommerce_coupon_get_maximum_amount', [ $this, 'get_coupon_min_max_amount' ], 50 );
add_filter( 'woocommerce_coupon_get_amount', [ $this, 'get_coupon_amount' ], 900, 2 );
add_filter( 'woocommerce_coupon_get_minimum_amount', [ $this, 'get_coupon_min_max_amount' ], 900 );
add_filter( 'woocommerce_coupon_get_maximum_amount', [ $this, 'get_coupon_min_max_amount' ], 900 );

// Order hooks.
add_filter( 'woocommerce_new_order', [ $this, 'add_order_meta' ], 50, 2 );
add_filter( 'woocommerce_new_order', [ $this, 'add_order_meta' ], 900, 2 );
}
}

Expand Down Expand Up @@ -215,7 +215,7 @@ public function register_free_shipping_filters() {
foreach ( $shipping_zone['shipping_methods'] as $shipping_method ) {
if ( 'free_shipping' === $shipping_method->id ) {
$option_name = 'option_woocommerce_' . trim( $shipping_method->id ) . '_' . (int) $shipping_method->instance_id . '_settings';
add_filter( $option_name, [ $this, 'get_free_shipping_min_amount' ], 50 );
add_filter( $option_name, [ $this, 'get_free_shipping_min_amount' ], 900 );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function tear_down() {
*/
public function test_registers_woocommerce_filter( $filter, $function_name ) {
$this->assertGreaterThan(
10,
500,
has_filter( $filter, [ $this->frontend_currencies, $function_name ] ),
"Filter '$filter' was not registered with '$function_name' with a priority higher than the default"
);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/multi-currency/test-class-frontend-prices.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function tear_down() {
*/
public function test_registers_woocommerce_filter( $filter, $function_name ) {
$this->assertGreaterThan(
10,
500,
has_filter( $filter, [ $this->frontend_prices, $function_name ] ),
"Filter '$filter' was not registered with '$function_name' with a priority higher than the default"
);
Expand Down Expand Up @@ -90,8 +90,8 @@ public function test_registers_woocommerce_filters_for_free_shipping_methods() {

$this->frontend_prices->register_free_shipping_filters();

$this->assertGreaterThan( 10, has_filter( 'option_woocommerce_free_shipping_' . $default_zone_free_method . '_settings', [ $this->frontend_prices, 'get_free_shipping_min_amount' ] ) );
$this->assertGreaterThan( 10, has_filter( 'option_woocommerce_free_shipping_' . $new_zone_free_method . '_settings', [ $this->frontend_prices, 'get_free_shipping_min_amount' ] ) );
$this->assertGreaterThan( 500, has_filter( 'option_woocommerce_free_shipping_' . $default_zone_free_method . '_settings', [ $this->frontend_prices, 'get_free_shipping_min_amount' ] ) );
$this->assertGreaterThan( 500, has_filter( 'option_woocommerce_free_shipping_' . $new_zone_free_method . '_settings', [ $this->frontend_prices, 'get_free_shipping_min_amount' ] ) );
}

public function test_get_product_price_returns_empty_price() {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/multi-currency/test-class-multi-currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function test_get_available_currencies_adds_store_currency() {
function () {
return 'DEFAULT';
},
100
901
);

$this->init_multi_currency();
Expand Down