Fixes possible fatal error in legacy report code (#38683)

This commit is contained in:
Ron Rennick 2023-06-13 09:47:51 -03:00 committed by GitHub
commit 81a5a435fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Handle possibly empty refund value in reports (PHP 8.1+).

View File

@ -512,7 +512,7 @@ class WC_Admin_Report {
}
if ( $data_key ) {
$prepared_data[ $time ][1] += $d->$data_key;
$prepared_data[ $time ][1] += is_numeric( $d->$data_key ) ? $d->$data_key : 0;
} else {
$prepared_data[ $time ][1] ++;
}

View File

@ -326,7 +326,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
);
foreach ( $this->report_data->partial_refunds as $key => $order ) {
$this->report_data->partial_refunds[ $key ]->net_refund = $order->total_refund - ( $order->total_shipping + $order->total_tax + $order->total_shipping_tax );
$this->report_data->partial_refunds[ $key ]->net_refund = (float) $order->total_refund - ( (float) $order->total_shipping + (float) $order->total_tax + (float) $order->total_shipping_tax );
}
/**