diff --git a/plugins/woocommerce/changelog/fix-49635-tax-totals-filter b/plugins/woocommerce/changelog/fix-49635-tax-totals-filter new file mode 100644 index 00000000000..785feb82e13 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-49635-tax-totals-filter @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Use `get_filtered_ids` consistently in `reports/taxes` and `reports/taxes/stats` datastores diff --git a/plugins/woocommerce/src/Admin/API/Reports/Taxes/DataStore.php b/plugins/woocommerce/src/Admin/API/Reports/Taxes/DataStore.php index d808b8170fb..0ff5742e014 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Taxes/DataStore.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Taxes/DataStore.php @@ -124,6 +124,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Updates the database query with parameters used for Taxes report: categories and order status. * + * @see Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats\DataStore::update_sql_query_params() * @param array $query_args Query arguments supplied by the user. */ protected function add_sql_query_params( $query_args ) { diff --git a/plugins/woocommerce/src/Admin/API/Reports/Taxes/Stats/DataStore.php b/plugins/woocommerce/src/Admin/API/Reports/Taxes/Stats/DataStore.php index 2173f6b859c..3e124ad2396 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Taxes/Stats/DataStore.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Taxes/Stats/DataStore.php @@ -79,28 +79,29 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Updates the database query with parameters used for Taxes Stats report * + * @see Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore::add_sql_query_params() * @param array $query_args Query arguments supplied by the user. */ protected function update_sql_query_params( $query_args ) { global $wpdb; - $taxes_where_clause = ''; $order_tax_lookup_table = self::get_db_table_name(); + $this->add_time_period_sql_params( $query_args, $order_tax_lookup_table ); + $taxes_where_clause = ''; + $order_status_filter = $this->get_status_subquery( $query_args ); + if ( isset( $query_args['taxes'] ) && ! empty( $query_args['taxes'] ) ) { - $query_args['taxes'] = (array) $query_args['taxes']; - $tax_id_placeholders = implode( ',', array_fill( 0, count( $query_args['taxes'] ), '%d' ) ); - /* phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared */ - $taxes_where_clause .= $wpdb->prepare( " AND {$order_tax_lookup_table}.tax_rate_id IN ({$tax_id_placeholders})", $query_args['taxes'] ); + $allowed_taxes = self::get_filtered_ids( $query_args, 'taxes' ); + /* phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- `$allowed_taxes` was prepared by get_filtered_ids above. */ + $taxes_where_clause .= " AND {$order_tax_lookup_table}.tax_rate_id IN ({$allowed_taxes})"; /* phpcs:enable */ } - $order_status_filter = $this->get_status_subquery( $query_args ); if ( $order_status_filter ) { $taxes_where_clause .= " AND ( {$order_status_filter} )"; } - $this->add_time_period_sql_params( $query_args, $order_tax_lookup_table ); $this->total_query->add_sql_clause( 'where', $taxes_where_clause ); $this->add_intervals_sql_params( $query_args, $order_tax_lookup_table );