__( 'Year', 'woocommerce' ), 'last_month' => __( 'Last month', 'woocommerce' ), 'month' => __( 'This month', 'woocommerce' ), ); $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : 'last_month'; if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) { $current_range = 'last_month'; } $this->check_current_range_nonce( $current_range ); $this->calculate_current_range( $current_range ); $hide_sidebar = true; include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' ); } /** * Get the main chart. * * @return string */ public function get_main_chart() { global $wpdb; $query_data = array( 'order_item_name' => array( 'type' => 'order_item', 'function' => '', 'name' => 'tax_rate', ), 'tax_amount' => array( 'type' => 'order_item_meta', 'order_item_type' => 'tax', 'function' => '', 'name' => 'tax_amount', ), 'shipping_tax_amount' => array( 'type' => 'order_item_meta', 'order_item_type' => 'tax', 'function' => '', 'name' => 'shipping_tax_amount', ), 'rate_id' => array( 'type' => 'order_item_meta', 'order_item_type' => 'tax', 'function' => '', 'name' => 'rate_id', ), 'ID' => array( 'type' => 'post_data', 'function' => '', 'name' => 'post_id', ), ); $query_where = array( array( 'key' => 'order_item_type', 'value' => 'tax', 'operator' => '=', ), array( 'key' => 'order_item_name', 'value' => '', 'operator' => '!=', ), ); $tax_rows_orders = $this->get_order_report_data( array( 'data' => $query_data, 'where' => $query_where, 'order_by' => 'posts.post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => array_merge( wc_get_order_types( 'sales-reports' ), array( 'shop_order_refund' ) ), 'order_status' => array( 'completed', 'processing', 'on-hold' ), 'parent_order_status' => array( 'completed', 'processing', 'on-hold' ), // Partial refunds inside refunded orders should be ignored ) ); // Merge $tax_rows = array(); foreach ( $tax_rows_orders as $tax_row ) { $key = $tax_row->rate_id; $tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array( 'tax_amount' => 0, 'shipping_tax_amount' => 0, 'total_orders' => 0 ); if ( 'shop_order_refund' !== get_post_type( $tax_row->post_id ) ) { $tax_rows[ $key ]->total_orders += 1; } $tax_rows[ $key ]->tax_rate = $tax_row->tax_rate; $tax_rows[ $key ]->tax_amount += wc_round_tax_total( $tax_row->tax_amount ); $tax_rows[ $key ]->shipping_tax_amount += wc_round_tax_total( $tax_row->shipping_tax_amount ); } ?> $tax_row ) { $rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $rate_id ) ); ?>
tax_rate, $rate_id, $tax_row ); ?> % total_orders; ?> tax_amount ); ?> shipping_tax_amount ); ?> tax_amount + $tax_row->shipping_tax_amount ); ?>