Skip to:
Content
Pages
Categories
Search
Top
Bottom

show profile fields as currency and %

  • @commoneasy

    Participant

    Hi there,

    i´am looking for a way to show profile fields as a currency or a percentage. I use the xprofile custom profile fields plugin to use some profile fields as number fields. However it doesn´t support a currency filter jet. I tried to following code in the custom profile fields plugin on advice as a first step:

    add_filter( 'bxcft_show_field_value', 'my_show_field', 15, 4);
    function my_show_field($value_to_return, $type, $id, $value) {
        if ($type == 'number') {
            $value = str_replace("<p>", "", $value);
            $value = str_replace("</p>", "", $value);
            $field = new BP_XProfile_Field($id);
            if ($field->name == 'Waarde van je gadget (€)') {
    		     setlocale(LC_MONETARY, 'nl_NL');
                $value = money_format('%.2n', $value) . "\n";
                $new_value = money_format('%.2n', $value) . "\n";
            } else {
                $new_value = $value;
            }
            return '<p>'.$new_value.'</p>';
        }
        return $value_to_return;
    }

    this code should change profile field 15 to a currency, unfortunatly it didn’t work. I hope there is a way to do this in buddypress itself. Can somebody please help me to the right direction? many many thanks in advance 🙂

Viewing 1 replies (of 1 total)
  • @commoneasy

    Participant

    I got this working with:

    add_filter( 'bxcft_show_field_value', 'my_show_field', 15, 4);
    function my_show_field($value_to_return, $type, $id, $value) {
      if ($value_to_return == '')
            return $value_to_return;   
       if ($type == 'number') {
            $value = str_replace("<p>", "", $value);
            $value = str_replace("</p>", "", $value);
            $field = new BP_XProfile_Field($id);
            if ($field->id == '18' ) {
    		  
    
    	 $f_value=number_format($value,2);
    			  $new_value = "&euro; $f_value,-";
           
    
    	   } else {
                $new_value = $value;
            }
            return '<p>'.$new_value.'</p>';
        }
        return $value_to_return;
    }

    Does anybody have an idea how i can use this for multiple fields? strangely something like ‘2,18,19’ isn’t working…

Viewing 1 replies (of 1 total)
  • The topic ‘show profile fields as currency and %’ is closed to new replies.
Skip to toolbar