0 ) { $s = str_pad( $s, $minor_unit + 1, '0', STR_PAD_LEFT ); $s = substr( $s, 0, -$minor_unit ) . '.' . substr( $s, -$minor_unit ); } return array( 'amount' => ( $neg ? '-' : '' ) . $s, 'currency' => $currency ); } /** * From a WooCommerce decimal price string to the same shape. * * @param string|float|null $amount Price as WooCommerce stores it. * @param string $currency ISO 4217 code. * @return array{amount: string, currency: string}|null */ public static function from_decimal( $amount, string $currency ): ?array { if ( null === $amount || '' === $amount ) { return null; } return array( 'amount' => wc_format_decimal( $amount, wc_get_price_decimals() ), 'currency' => $currency ); } /** * JSON Schema for a money object. * * @return array */ public static function schema(): array { return array( 'type' => array( 'object', 'null' ), 'properties' => array( 'amount' => array( 'type' => 'string', 'description' => 'Decimal amount, e.g. "19.99".' ), 'currency' => array( 'type' => 'string', 'description' => 'ISO 4217 code.' ), ), ); } }