diff --git a/inc/Formatting/FieldFormatter.php b/inc/Formatting/FieldFormatter.php index f86571ac..01a9ebe9 100644 --- a/inc/Formatting/FieldFormatter.php +++ b/inc/Formatting/FieldFormatter.php @@ -17,6 +17,11 @@ final class FieldFormatter { * @psalm-suppress UndefinedClass */ public static function format_currency( mixed $value, ?string $iso_4127_currency_code = null, ?string $locale = null ): string { + // The PHP 'intl' extension is not available in WordPress Playground. + if ( ! class_exists( 'NumberFormatter' ) || ! function_exists( 'numfmt_create' ) ) { + return strval($value); + } + $format = numfmt_create( $locale ?? get_locale(), NumberFormatter::CURRENCY ); $currency_code = $iso_4127_currency_code ?? $format->getTextAttribute( NumberFormatter::CURRENCY_CODE ); return numfmt_format_currency( $format, (float) $value, $currency_code );