Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Adding BP group name or ID to woocommerce orders list page in admin

@kailanw

Participant

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 );
}
Skip to toolbar