• Resolved eavinu

    (@eavinu)


    Hello,
    I am trying to show the Buddypress group/s name as a column under the users list and also under woocommerce orders list.

    For the users list I could only find a custom field for the Group ID, any idea on how I could show the group name?

    As for the woocommerce orders page, how could I show a column of the customer’s registered BP groups at all?

    Hope that someone could help with this as I must accomplish this somehow.
    Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Stefan van den Dungen Gronovius

    (@dungengronovius)

    I’m not familiar with the Buddypress plugin but tried to reproduce the issue to see if I can get the Group ID column on my user list. I did not found the group_id in my custom field column, but if you found the group_id and this is the ID for the Buddypress Group, you could change the Field type to ‘Post Title’. It should show you the title of that post (group).

    Showing User info on the WooCommerce Order page is a great idea, but unfortunately our plugin can only show fields that are related to current post type, in this case a WooCommerce order. The user is stored as ID to an order but the group is a lever deeper.

    The pro version of our plugin has a WooCommerce Addon for Admin Columns and this feature could be a nice addition to this addon, but for now it is not possible to show the BP Group on the WooCommerce Order overview, unless you create the column yourself.

    If you feel comfortable writing code, you could have a look at this page.
    https://www.admincolumns.com/documentation/developer-docs/creating-new-column-type/

    Thread Starter eavinu

    (@eavinu)

    Thank you for the fast reply and interest to help with this issue!

    Actually the custom field name in order to show the group ID is “field_reg_groups”.
    So I changed the field type to ‘post_title’ and it shows nothing…
    I did make sure that the ID’s that I see when field type is default are indeed the ID’s for the groups…
    Any ideas?
    Perhaps you might have an idea after reading this post:
    https://buddypress.org/support/topic/getting-group-name-from-id/

    About the woocommerce orders page, I will check the link that you sent, hope that I am skilled enough to handle writing it ??

    Plugin Author Stefan van den Dungen Gronovius

    (@dungengronovius)

    Based on your custom field key and the link you’ve send me, you should be able to show the group name by using this filter when the following conditions are true

    – Custom Field column is used
    – Custom Field key = ‘field_reg_groups’

    function cac_column_meta_value_group_name( $value, $object_id, $column ) {
    	$custom_field_key = 'field_reg_groups';
    
    	if ( 'column-meta' == $column->get_type() && $custom_field_key == $column->get_field() && $value ) {
    		// Value is a group ID here
    		if( $group = groups_get_group( array( 'group_id' => $value ) ) ){
    			$value = $group->name;
    		}
    	}
    
    	return $value;
    }
    add_filter( 'cac/column/meta/value', 'cac_column_meta_value_group_name', 10, 3 );
    Thread Starter eavinu

    (@eavinu)

    Perfect!!!

    Now I have 2 main issues with the site owner.. I need to make the column sortable + I need to have the groups column also in the Woocommerce orders page and make it sortable.

    If you are able to help, or even have some one that would be able to help with the 2 issues I will be greatful and will be happy to donate or pay for the time it should take to you or someone else to code this.

    Hope to achieve this soon.. Until I get a reply here I will continue break my fingers trying to get it to sort.. Found some posts with suggestions that I still didn’t manage to customize for my column:

    // Make these columns sortable
    function sortable_columns() {
      return array(
        'YOURCOLUMNNAME'      => 'YOURCOLUMNNAME'
      );
    }
    
    add_filter( "manage_edit-YOURPOSTTYPENAME_sortable_columns", "sortable_columns" );
    Thread Starter eavinu

    (@eavinu)

    Actually what they want more is the ability to filter, they need it more then sorting…

    Plugin Author Stefan van den Dungen Gronovius

    (@dungengronovius)

    The pro version of our plugin allow you to filter and sort on custom field columns, but in this case this also work only on the Group ID instead of the actual group name. So it will work, but the filter dropdown will show you ID’s instead of names. You could add an ID column so that the reference is easily made, but I understand that this is not the ideal solution.

    Unfortunately we cannot help you with writing this custom feature but I believe that most WordPress developer can help you with this problem.

    Thread Starter eavinu

    (@eavinu)

    First of all thank you very much for all of your help!

    I will check with them and if they ask me too I will buy the pro version in order to be able to sort in the users list.

    For Woocommerce, I found this:

    add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
    function MY_COLUMNS_FUNCTION($columns){
        $new_columns = (is_array($columns)) ? $columns : array();
        unset( $new_columns['order_actions'] );
    
        //edit this for you column(s)
        //all of your columns will be added before the actions column
        $new_columns['MY_COLUMN_ID_1'] = 'MY_COLUMN_1_TITLE';
        $new_columns['MY_COLUMN_ID_2'] = 'MY_COLUMN_2_TITLE';
        //stop editing
    
        $new_columns['order_actions'] = $columns['order_actions'];
        return $new_columns;
    }
    
    add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
    function MY_COLUMNS_VALUES_FUNCTION($column){
        global $post;
        $data = get_post_meta( $post->ID );
    
        //start editing, I was saving my fields for the orders as custom post meta
        //if you did the same, follow this code
        if ( $column == 'MY_COLUMN_ID_1' ) {    
            echo (isset($data['MY_COLUMN_1_POST_META_ID']) ? $data['MY_COLUMN_1_POST_META_ID'] : '');
        }
        if ( $column == 'MY_COLUMN_ID_2' ) {    
            echo (isset($data['MY_COLUMN_2_POST_META_ID']) ? $data['MY_COLUMN_2_POST_META_ID'] : '');
        }
        //stop editing
    }
    
    add_filter( "manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION' );
    function MY_COLUMNS_SORT_FUNCTION( $columns ) {
        $custom = array(
            //start editing
    
            'MY_COLUMN_ID_1'    => 'MY_COLUMN_1_POST_META_ID',
            'MY_COLUMN_ID_2'    => 'MY_COLUMN_2_POST_META_ID'
    
            //stop editing
        );
        return wp_parse_args( $custom, $columns );
    }

    What I am missing is the column ID to use instead of ‘MY_COLUMN_ID_1’ and the value I should use for ‘MY_COLUMN_1_POST_META_ID’.
    As well I am sure there is something that I need to add to the function/s in order to be able to get the values…
    Any chance to get any help with this?
    Even paid help if it is complicated…

    And again thank you very much!

    Plugin Author Stefan van den Dungen Gronovius

    (@dungengronovius)

    In this example the ID ‘MY_COLUMN_ID_1’ is something you can change to whatever you like. Just be sure you use it consistently in all the functions. You post meta ID will be ‘field_reg_groups’. This example is just for making a column sortable. You still have to do the actual sorting which is not written in this snippet. You can have a look at this article
    https://code.tutsplus.com/articles/quick-tip-make-your-custom-column-sortable–wp-25095

    I can’t help you further with this problem and you have to write your own code or find someone who will help you with this, but we can’t do paid support for you.

    Thread Starter eavinu

    (@eavinu)

    Thank you very much!
    You have been very helpful as it is.
    Really appreciated.

    I still didn’t manage to get this field to be sortable under woocommerce orders but will update here if i do manage to do it.

    Meanwhile I also purchased (to extend the managing capabilities of the site admin) the plugin Users Insight and it gives great filtering capabilities for users info.

    Thanks Again for your time and assistance.

    CoreyFF

    (@coreyff)

    I’m also looking to list BuddyPress groups for each user without writing a custom column (to retain filtering ability).

    @eavinu – I don’t see the field “field_reg_groups” available anywhere in the Admin Column Pro interface (it sounds like @dungengronovius didn’t see it either).

    Would you mind posting a screenshot or explaining how you were able to make that field available as a column?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘buddypress group name colum’ is closed to new replies.