Automattic\WooCommerce\Internal\RestApi\Routes\V4\Refunds
DataUtils::calculate_refund_amount
Calculate the refund amount from line items.
Method of the class: DataUtils{}
No Hooks.
Returns
float|null. The refund amount, or null if it can't be calculated.
Usage
$DataUtils = new DataUtils(); $DataUtils->calculate_refund_amount( $line_items ): ?float;
- $line_items(array) (required)
- The line items to calculate the refund amount from.
DataUtils::calculate_refund_amount() DataUtils::calculate refund amount code WC 10.4.3
public function calculate_refund_amount( array $line_items ): ?float {
if ( empty( $line_items ) ) {
return null;
}
$amount = 0;
foreach ( $line_items as $line_item ) {
if ( ! empty( $line_item['refund_total'] ) && is_numeric( $line_item['refund_total'] ) ) {
$amount += $line_item['refund_total'];
}
if ( ! empty( $line_item['refund_tax'] ) && is_array( $line_item['refund_tax'] ) ) {
foreach ( $line_item['refund_tax'] as $tax ) {
if ( ! empty( $tax['refund_total'] ) && is_numeric( $tax['refund_total'] ) ) {
$amount += $tax['refund_total'];
}
}
}
}
return $amount;
}