WooCommerce Currency Switcher cant by default work with WooCommerce reports as there is no hooks there, and its not possible to plug-in there. But after some investigations of woocommerce code I found 1 way how to adapt reports for orders with different currencies (works only for Reports->Orders->”Sales by date”):
- open file wp-content\plugins\woocommerce\includes\admin\reports\class-wc-admin-report.php
- find there public function get_order_report_data
- on the same end of the function before code return $result; drop code:1$result = apply_filters('woocs_reports_get_order_report_query', $result, $args);
- open functions.php file of your current wp theme and on the same bottom of the file drop the next code:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687add_filter('woocs_reports_get_order_report_query', function($result, $args) {if (is_array($result) AND isset($result[0]->total_sales)){global $wpdb;global $WOOCS;$range = '7day';if (isset($_GET['range'])){$range = $_GET['range'];}$start_date = '';$end_date = date('Y-m-d 23:59:59');switch ($range){case 'custom':$start_date = $_GET['start_date'];break;case '7day':$start_date = date('Y-m-d 00:00:00', time() - 7 * DAY_IN_SECONDS);break;case 'month':$start_date = date('Y-m-01 00:00:00');break;case 'year':$start_date = date('Y-01-01 00:00:00');break;default:$start_date = date('Y-m-d 00:00:00', time() - 7 * DAY_IN_SECONDS);break;}$order_status = "wc-" . implode('","wc-', $args['order_status']);//***$sql = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status IN("' . $order_status . '") AND post_date >= %s AND post_date < %s', 'shop_order', $start_date, $end_date);$tmp = $wpdb->get_results($sql, ARRAY_N);$orders = array();$result = array();if (!empty($tmp)){foreach ($tmp as $v){$orders[] = $v[0];}$result = array();$currencies = $WOOCS->get_currencies();foreach ($orders as $order_id){$tmp = array();$order = new WC_Order($order_id);$_order_currency = get_post_meta($order_id, '_order_currency', true);$order_rate = get_post_meta($order_id, '_woocs_order_rate', true);if (!$order_rate){if (isset($currencies[$_order_currency])){$order_rate = $currencies[$_order_currency]['rate'];} else{continue;}}if ($_order_currency != $WOOCS->default_currency){$tmp['total_sales'] = $WOOCS->back_convert(get_post_meta($order_id, '_order_total', true), $order_rate, 4);$tmp['total_shipping'] = $WOOCS->back_convert(get_post_meta($order_id, '_order_shipping', true), $order_rate, 4);$tmp['total_tax'] = $WOOCS->back_convert(get_post_meta($order_id, '_order_tax', true), $order_rate, 4);$tmp['total_shipping_tax'] = $WOOCS->back_convert(get_post_meta($order_id, '_order_shipping_tax', true), $order_rate, 4);} else{$tmp['total_sales'] = get_post_meta($order_id, '_order_total', true);$tmp['total_shipping'] = get_post_meta($order_id, '_order_shipping', true);$tmp['total_tax'] = get_post_meta($order_id, '_order_tax', true);$tmp['total_shipping_tax'] = get_post_meta($order_id, '_order_shipping_tax', true);}$tmp['post_date'] = $order->order_date;$result[] = (object) $tmp;}}}return $result;}, 10, 2);
