Last active
September 5, 2024 18:59
-
-
Save zackpyle/4f412fcbd1a2fb52fcbe57ba67bb9a30 to your computer and use it in GitHub Desktop.
Format ACF Number fields with Commas on the Frontend #acf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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