Automattic\WooCommerce\Internal\RestApi\Routes\V4\Refunds

DataUtils::normalize_refund_totals │ public │ WC 10.9.0

Round every caller-supplied refund_total to currency precision.

Applied at the entry of both the preview and create flows so a value the client sends is validated, summed, split, and stored at the same precision. A previewed amount therefore always matches the created refund to the cent. A missing or null refund_total (the auto-compute form) is left untouched — those are computed later and already rounded by {@see compute_line_item_refund_total()}.

Метод класса: DataUtils{}

Хуков нет.

Возвращает

array. Line items with numeric refund_total values rounded to wc_get_price_decimals().

Использование

$DataUtils = new DataUtils();
$DataUtils->normalize_refund_totals( $line_items ): array;
$line_items(массив) (обязательный)
Line items in schema format.

Список изменений

С версии 10.9.0 Введена.

Код DataUtils::normalize_refund_totals() WC 11.2.2

public function normalize_refund_totals( array $line_items ): array {
	$price_decimals = wc_get_price_decimals();
	foreach ( $line_items as $key => $line_item ) {
		if ( isset( $line_item['refund_total'] ) && is_numeric( $line_item['refund_total'] ) ) {
			$line_items[ $key ]['refund_total'] = NumberUtil::round( (float) $line_item['refund_total'], $price_decimals );
		}
	}
	return $line_items;
}