Skip to content

Commit

Permalink
Fix deprecated strtolower on order received page (#8387)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Jinks <[email protected]>
Co-authored-by: Miguel Gasca <[email protected]>
Co-authored-by: deepakpathania <[email protected]>
  • Loading branch information
4 people authored Mar 18, 2024
1 parent f15c223 commit 86af532
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

strtolower deprecation warning no longer appears on the Order Received and View Order pages when using PHP version 8.1+
21 changes: 20 additions & 1 deletion includes/multi-currency/FrontendCurrencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ public function init_hooks() {
// Currency hooks.
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_action( 'woocommerce_order_get_total', [ $this, 'maybe_init_order_currency_from_order_total_prop' ], 900, 2 );
add_action( 'woocommerce_get_formatted_order_total', [ $this, 'maybe_clear_order_currency_after_formatted_order_total' ], 900, 4 );

// Note: it's important that 'init_order_currency_from_query_vars' is called before
// 'get_price_decimal_separator' because the order currency is often required to
// determine the decimal separator. That's why the priority on 'init_order_currency_from_query_vars'
// is explicity lower than the priority of 'get_price_decimal_separator'.
add_filter( 'wc_get_price_decimal_separator', [ $this, 'init_order_currency_from_query_vars' ], 900 );
add_filter( 'wc_get_price_decimal_separator', [ $this, 'get_price_decimal_separator' ], 901 );
}

add_filter( 'woocommerce_thankyou_order_id', [ $this, 'init_order_currency' ] );
Expand Down Expand Up @@ -270,7 +276,16 @@ public function init_order_currency( $arg ) {
return $arg;
}

// We remove the filters here becuase 'wc_get_order' triggers the 'wc_get_price_decimal_separator' filter.
remove_filter( 'wc_get_price_decimal_separator', [ $this, 'get_price_decimal_separator' ], 901 );
remove_filter( 'wc_get_price_decimal_separator', [ $this, 'init_order_currency_from_query_vars' ], 900 );
$order = ! $arg instanceof WC_Order ? wc_get_order( $arg ) : $arg;
// Note: it's important that 'init_order_currency_from_query_vars' is called before
// 'get_price_decimal_separator' because the order currency is often required to
// determine the decimal separator. That's why the priority on 'init_order_currency_from_query_vars'
// is explicity lower than the priority of 'get_price_decimal_separator'.
add_filter( 'wc_get_price_decimal_separator', [ $this, 'init_order_currency_from_query_vars' ], 900 );
add_filter( 'wc_get_price_decimal_separator', [ $this, 'get_price_decimal_separator' ], 901 );

if ( $order ) {
$this->order_currency = $order->get_currency();
Expand All @@ -290,6 +305,10 @@ public function init_order_currency_from_query_vars() {
global $wp;
if ( ! empty( $wp->query_vars['order-pay'] ) ) {
$this->init_order_currency( $wp->query_vars['order-pay'] );
} elseif ( ! empty( $wp->query_vars['order-received'] ) ) {
$this->init_order_currency( $wp->query_vars['order-received'] );
} elseif ( ! empty( $wp->query_vars['view-order'] ) ) {
$this->init_order_currency( $wp->query_vars['view-order'] );
}
}

Expand Down

0 comments on commit 86af532

Please sign in to comment.