Skip to content

Instantly share code, notes, and snippets.

@zackpyle
Last active May 30, 2024 20:25
Show Gist options
  • Save zackpyle/4f412fcbd1a2fb52fcbe57ba67bb9a30 to your computer and use it in GitHub Desktop.
Save zackpyle/4f412fcbd1a2fb52fcbe57ba67bb9a30 to your computer and use it in GitHub Desktop.
Format ACF Number fields with Commas on the Frontend #acf
<?php
// Return ACF Number Fields Formatted with Commas on the Frontend
add_filter('acf/format_value/name=ACF_FIELD_NAME', 'acf_number_comma', 20, 3);
add_filter('acf/format_value/name=ANOTHER_ACF_FIELD_NAME', 'acf_number_comma_decimal', 20, 3);
// Without Decimal
function acf_number_comma($value, $post_id, $field) {
$value = number_format(floatval($value));
return $value;
}
// With Decimal
function acf_number_comma_decimal($value, $post_id, $field) {
$value = number_format(floatval($value), 2);
return $value;
}
//Use to convert all number fields
//add_filter('acf/format_value/type=number', 'acf_number_comma', 30, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment