@kailanw
Active 4 months, 2 weeks ago
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
I forgot to subscribe to the post via email. The code below will give you the group names instead of group ID.
Unfortunately, I am not sure how to sort by Groups at the moment. The reason is because Orders are a post type and doesn’t necessarily have a relation to BuddyPress groups. So there isn’t an immediate query I can think of to make this sortable. I hope that makes sense.
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'] = 'סניף'; //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; // order id $order_id = $post->ID; // get Order object $order = new WC_Order( $order_id ); // get customer user id $user_id = $order->user_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' && $user_id ) { // get user groups $groups = groups_get_user_groups( $user_id ); if ( ! empty( $groups ) && ! empty( $groups['groups'] ) ) { $group_list = array(); foreach ( $groups['groups'] as $key => $group_id ) { $group = groups_get_group( array( 'group_id' => $group_id ) ); $group_list[] = $group->name; } // let's make a comma separated list of the group IDs echo implode( ', ', $group_list ); //if you would like to get just one group ID, uncomment the following //echo $groups['groups'][0]; } } //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' //stop editing ); return wp_parse_args( $custom, $columns ); }
You can use the following code to accomplish 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'] = 'סניף'; //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; // order id $order_id = $post->ID; // get Order object $order = new WC_Order( $order_id ); // get customer user id $user_id = $order->user_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' && $user_id ) { // get user groups $groups = groups_get_user_groups( $user_id ); if ( ! empty( $groups ) && ! empty( $groups['groups'] ) ) { // let's make a comma separated list of the group IDs echo implode( ',', $groups['groups'] ); //if you would like to get just one group ID, uncomment the following //echo $groups['groups'][0]; } } //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' //stop editing ); return wp_parse_args( $custom, $columns ); }
Viewing 2 replies - 1 through 2 (of 2 total)