Fix number of orders under tax report (#38525)

* Count unique post_id

* Add changelog

* Fix lint

* Fix Reports table

* Fix lint

* Fix $key
This commit is contained in:
Fernando Marichal 2023-06-15 11:11:10 -03:00 committed by GitHub
parent 5f94b411f0
commit d74904b1bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Fix number of orders under tax report

View File

@ -158,22 +158,28 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
// Merge.
$tax_rows = array();
// Initialize an associative array to store unique post_ids.
$unique_post_ids = array();
foreach ( $tax_rows_orders + $tax_rows_partial_refunds as $tax_row ) {
$key = $tax_row->rate_id;
$key = $tax_row->tax_rate;
$tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array(
'tax_amount' => 0,
'shipping_tax_amount' => 0,
'total_orders' => 0,
);
$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 );
if ( ! isset( $unique_post_ids[ $key ] ) || ! in_array( $tax_row->post_id, $unique_post_ids[ $key ], true ) ) {
$unique_post_ids[ $key ] = isset( $unique_post_ids[ $key ] ) ? $unique_post_ids[ $key ] : array();
$unique_post_ids[ $key ][] = $tax_row->post_id;
$tax_rows[ $key ]->total_orders += 1;
}
}
foreach ( $tax_rows_full_refunds as $tax_row ) {
$key = $tax_row->rate_id;
$key = $tax_row->tax_rate;
$tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array(
'tax_amount' => 0,
'shipping_tax_amount' => 0,