From 86af532a92b80cd3142bb2671cb27cf0d4bd3c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3fer=20Reykjal=C3=ADn?= <13835680+reykjalin@users.noreply.github.com> Date: Mon, 18 Mar 2024 19:29:17 +0000 Subject: [PATCH] Fix deprecated strtolower on order received page (#8387) Co-authored-by: Eric Jinks <3147296+Jinksi@users.noreply.github.com> Co-authored-by: Miguel Gasca Co-authored-by: deepakpathania <68396823+deepakpathania@users.noreply.github.com> --- ...precated-strtolower-on-order-received-page | 4 ++++ .../multi-currency/FrontendCurrencies.php | 21 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 changelog/fix-8232-deprecated-strtolower-on-order-received-page diff --git a/changelog/fix-8232-deprecated-strtolower-on-order-received-page b/changelog/fix-8232-deprecated-strtolower-on-order-received-page new file mode 100644 index 00000000000..f3b3df52ce6 --- /dev/null +++ b/changelog/fix-8232-deprecated-strtolower-on-order-received-page @@ -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+ diff --git a/includes/multi-currency/FrontendCurrencies.php b/includes/multi-currency/FrontendCurrencies.php index fd38135b230..0c5fdf46821 100644 --- a/includes/multi-currency/FrontendCurrencies.php +++ b/includes/multi-currency/FrontendCurrencies.php @@ -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' ] ); @@ -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(); @@ -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'] ); } }