Hey @kuschang,
I believe the following code should help with this:
/**
* Registers the "referred_affiliates" column in the admin affiliates table, right after the "name" column.
*
* @param array $columns
*
* @return array
*
*/
function slicewp_custom_add_affiliate_admin_table_column_referred_affiliates( $columns ) {
$columns = array_merge(
array_slice( $columns, 1, array_search( 'name', array_keys( $columns ) ) ),
array( 'referred_affiliates' => 'Referred Affiliates' ),
array_slice( $columns, array_search( 'name', array_keys( $columns ) ) + 1, count( $columns ) )
);
return $columns;
}
add_filter( 'slicewp_list_table_affiliates_columns', 'slicewp_custom_add_affiliate_admin_table_column_referred_affiliates' );
/**
* Appends the HTML that should be shown in the "parent" column of the admin affiliates table.
*
* @param array $row_data
*
* @return array
*
*/
function slicewp_custom_add_affiliate_referred_affiliates_to_affiliate_admin_table_data_row( $row_data ) {
if ( empty( $row_data['id'] ) ) {
return $row_data;
}
$affiliates_count = slicewp_get_affiliates( array( 'parent_id' => $row_data['id'] ), true );
$row_data['referred_affiliates'] = $affiliates_count;
return $row_data;
}
add_filter( 'slicewp_list_table_affiliates_row_data', 'slicewp_custom_add_affiliate_referred_affiliates_to_affiliate_admin_table_data_row' );
Please add the code to your website and let me know how it goes. Also, feel free to adapt it to your needs.
Thank you and best wishes,
Mihai