• Hi,

    I am using 3 point types.

    In the front end I use the following shortcode to show a total of all types of points.

    [mycred_total_balance types=”mycred_default,mycred_type1,mycred_type2″ raw=”1″]

    In the documentation of this shortcode, it says as follows,

    Attribute Type Default Required
    raw ( int ) 0 no

    Option to return the amount without any formatting (1) or return the total formatted (1).

    Both the options are 1 ?(bolded in above)

    I am confused, which to use to show the total point in formatting style ? I have tried with both, raw=”0″ and raw=”1″ nothing works. The total balance is not formatted with proper separator and pre-fix.

    And my another query, how can I use this in the in admin back-end, where I should have an column for total points, like that of all point type have. So, that I can track the total point. Also, any idea to add it to the wordpress dashboard ?

    https://wordpress.org/plugins/mycred/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author myCred

    (@designbymerovingi)

    Hi.

    Ups you are right, that is a bit confusing.

    So if you do not want the amount formatted then you use 0 and if you do want to format the total then you use 1. Since 0 is the default value, you do not define the attribute if you do not want things formatted.

    Next I should explain that formatted does not mean “including suffix and/or prefix”. It will format the value according to: your decimal setup and decimal / thousand separator setup.

    Thread Starter chakladar

    (@chakladar)

    Hi, Thanks for updating the shortcodes documents.

    You may have misunderstood my point. I want it to be formatted.

    BTW, I can add suffix by html. I need the thousand separator.

    [mycred_total_balance types=”mycred_default,mycred_type1,mycred_type2″ raw=”1″]

    see above, I have used 1, but it is not including the thousand seperator.

    Any way how can I add this column in the back-end ?

    Plugin Author myCred

    (@designbymerovingi)

    Are you looking to add up all point types and add it as a custom column when you are on the Users page?

    After some further digging I found that the shortcode does not include the seperators as I mentioned. I will have this fixed in 1.6.2. Until then you can use the following code snippet to fix this:

    add_filter( 'mycred_total_balances_output', 'mycred_pro_format_total_shortocode' );
    function mycred_pro_format_total_shortocode( $total ) {
    
    	return number_format( $total, 2, '.', ',' );
    
    }

    The above code goes into your child theme’s functions.php file and will convert the total into 2 decimals using dot for decimal separator and a comma sign for thousand.

    Thread Starter chakladar

    (@chakladar)

    Thanks for your quick reply.

    Are you looking to add up all point types and add it as a custom column when you are on the Users page?

    Yes, I was looking for that. How can I do this ?

    Thread Starter chakladar

    (@chakladar)

    Hi any suggestion ?

    Plugin Author myCred

    (@designbymerovingi)

    There are a lot of great tutorials on how to add a custom column in your admin area for your users list. Here is one example.

    Adding up all balances a user has it’s easy. You just need to loop through all point types that exists and add up each balance:

    $total = 0:
    if ( function_exists( 'mycred_get_types' ) ) {
    	$types = mycred_get_types();
    	foreach ( $types as $type_id => $label ) {
    		$balance = get_user_meta( $user_id, $type_id, true );
    		if ( $balance == '' ) continue;
    		$total = $total + $balance;
    	}
    }

    So using the example shown in the tutorial above you could use the two:

    // Add in the custom column
    add_filter('manage_users_columns', 'mycred_pro_add_custom_user_column');
    function mycred_pro_add_custom_user_column($columns) {
        $columns['mycred-total-all'] = 'Total Balance';
        return $columns;
    }
    
    // Add the custom columns content
    add_action('manage_users_custom_column',  'mycred_pro_show_custom_user_column', 10, 3);
    function mycred_pro_show_custom_user_column($value, $column_name, $user_id) {
    
    	if ( 'mycred-total-all' == $column_name ) {
    		$total = 0:
    		if ( function_exists( 'mycred_get_types' ) ) {
    			$types = mycred_get_types();
    			foreach ( $types as $type_id => $label ) {
    				$balance = get_user_meta( $user_id, $type_id, true );
    				if ( $balance == '' ) continue;
    				$total = $total + $balance;
    			}
    		}
    		$value = $total;
    	}
        return $value;
    }
    Thread Starter chakladar

    (@chakladar)

    Hi, thanks, that works. Just need to change, $total=0: to $total=0;

    But is not order-able by ascending or descending order like all point types can be ordered. How to do this ?

    Plugin Author myCred

    (@designbymerovingi)

    That is a bit more complicated because then you need to register your column to be sortable and then hook into the SQL Query for users and adjust it accordingly

    There are however a lot of great tutorials on the subject like this one by TUTS+. Otherwise I suggest you google “how to make custom column sortable”.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[mycred_total_balance] is not formatted’ is closed to new replies.