Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow

WebflowMapper::price_to_decimal │ private │ WC 1.0

Convert a Webflow money object { value: int (minor units), unit: "USD" } into a decimal string.

The number of minor units per major unit varies by currency (e.g. JPY has 0, KWD has 3, most have 2), so the divisor is derived from the currency's num_decimals rather than a hardcoded / 100.

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

Хуков нет.

Возвращает

string|null.

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

// private - только в коде основоного (родительского) класса
$result = $this->price_to_decimal( $money ): ?string;
$money(разное) (обязательный)
Webflow money object.

Код WebflowMapper::price_to_decimal() WC 11.2.2

private function price_to_decimal( $money ): ?string {
	if ( ! is_object( $money ) || ! isset( $money->value ) ) {
		return null;
	}
	$minor = (int) $money->value;
	if ( $minor < 0 ) {
		return null;
	}
	$unit     = isset( $money->unit ) ? (string) $money->unit : 'USD';
	$decimals = $this->get_currency_decimals( $unit );
	return number_format( $minor / ( 10 ** $decimals ), $decimals, '.', '' );
}