Guest User

Untitled

a guest
May 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: PDB Comma Decimal Separator Display
  4. * Description: alters the display of decimal numbers to use comma as the decimal separator, and point as the thousands separator
  5. */
  6. add_filter('pdb-before_display_form_element', 'xnau_show_comma_decimals', 10, 2 );
  7. function xnau_show_comma_decimals( $display, $field )
  8. {
  9. // we are only modifying these form element types
  10. if ( $field->form_element === 'decimal' || $field->form_element === 'currency' ) {
  11.  
  12. // count the number of decimal digits in the number
  13. $decimals = strlen( strstr( $field->value, '.' ) ) -1;
  14.  
  15. // this function formats the number using comma for the decimal separator and dot for the thousands separator
  16. $display = number_format( $field->value, $decimals, ',', '.' );
  17.  
  18. }
  19. return $display;
  20. }
Add Comment
Please, Sign In to add comment