pply the filtering. if ( has_action( MultiCurrency::FILTER_PREFIX . 'should_hide_widgets' ) ) { wc_deprecated_hook( MultiCurrency::FILTER_PREFIX . 'should_hide_widgets', '6.5.0', MultiCurrency::FILTER_PREFIX . 'should_disable_currency_switching' ); $return = apply_filters( MultiCurrency::FILTER_PREFIX . 'should_hide_widgets', $return ); } return apply_filters( MultiCurrency::FILTER_PREFIX . 'should_disable_currency_switching', $return ); } /** * Checks to see if the coupon's amount should be converted. * * @param object $coupon Coupon object to test. * * @return bool True if it should be converted. */ public function should_convert_coupon_amount( $coupon = null ): bool { if ( ! $coupon ) { return true; } return apply_filters( MultiCurrency::FILTER_PREFIX . 'should_convert_coupon_amount', true, $coupon ); } /** * Checks to see if the product's price should be converted. * * @param object $product Product object to test. * * @return bool True if it should be converted. */ public function should_convert_product_price( $product = null ): bool { if ( ! $product ) { return true; } return apply_filters( MultiCurrency::FILTER_PREFIX . 'should_convert_product_price', true, $product ); } /** * Determines if the store currency should be returned or not. * * @return bool */ public function should_return_store_currency(): bool { return apply_filters( MultiCurrency::FILTER_PREFIX . 'should_return_store_currency', false ); } /** * This filter is called when the best sales day logic is called. We use it to add another filter which will * convert the order prices used in this inbox notification. * * @param bool $arg Whether or not the best sales day logic should execute. We will just return this as is to * respect the existing behaviour. * * @return bool */ public function attach_order_modifier( $arg ) { // Attach our filter to modify the order prices. add_filter( 'woocommerce_order_query', [ $this, 'convert_order_prices' ] ); // This will be a bool value indication whether the best day logic should be run. Let's just return it as is. return $arg; } /** * When a request is made by the "Best Sales Day" Inbox notification, we want to hook into this and convert * the order totals to the store default currency. * * @param WC_Order[]|WC_Order_Refund[] $results The results returned by the orders query. * * @return array|object of WC_Order objects */ public function convert_order_prices( $results ) { $backtrace_calls = [ 'Automattic\WooCommerce\Admin\Notes\NewSalesRecord::sum_sales_for_date', 'Automattic\WooCommerce\Admin\Notes\NewSalesRecord::possibly_add_note', ]; // If the results are not an array, or if the call we're expecting isn't in the backtrace, then just do nothing and return the results. if ( ! is_array( $results ) || ! $this->utils->is_call_in_backtrace( $backtrace_calls ) ) { return $results; } $default_currency = $this->multi_currency->get_default_currency(); if ( ! $default_currency ) { return $results; } foreach ( $results as $order ) { if ( ! $order || $order->get_currency() === $default_currency->get_code() || ! $order->get_meta( '_wcpay_multi_currency_order_exchange_rate', true ) || $order->get_meta( '_wcpay_multi_currency_order_default_currency', true ) !== $default_currency->get_code() ) { continue; } $exchange_rate = $order->get_meta( '_wcpay_multi_currency_order_exchange_rate', true ); $order->set_total( number_format( $order->get_total() * ( 1 / $exchange_rate ), wc_get_price_decimals() ) ); } remove_filter( 'woocommerce_order_query', [ $this, 'convert_order_prices' ] ); return $results; } }