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
Yes it works again. You are awesome. Thanks @iovamihai
Hey @kuschang,
Happy to hear it’s working nicely! 😃
Best wishes,
Mihai
O yes, can I add this code to the dashboard of affiliate user account page so that user will know how many of affiliates he has already referred?
Thanks.
Ok, @iovamihai
One more thing. How do I make the referred affiliates count column sortable like ascending and descending?
Regards,
Rikiez
Hey @kuschang,
Unfortunately, due to how the database query system is built, this particular request cannot be implemented.
We currently don’t have a way to hook that deep into the plugin and alter the returned data by custom added table values.
As much as I’d love to help you out with this, currently I’m afraid that I don’t have a solution.
Best wishes,
Mihai
Ok no problem. Thanks anyway.