AffiliateWP - add affiliate's first and last name to the exported affiliates CSv file
<?php
/**
* Add 2 new columns to the exported affiliates's CSV file for the affiliates's first name and last name
*/
function affwp_custom_export_affiliates_csv_cols( $cols ) {
$cols['first_name'] = 'First Name';
$cols['last_name'] = 'Last Name';
return $cols;
}
add_filter( 'affwp_export_csv_cols_affiliates', 'affwp_custom_export_affiliates_csv_cols' );
/**
* Add the affiliates's first and last name to the .csv columns
*/
function affwp_custom_export_get_data_affiliates( $data ) {
foreach ( $data as $key => $d ) {
$user = get_user_by( 'email', $d['email'] );
$data[$key]['first_name'] = $user->first_name;
$data[$key]['last_name'] = $user->last_name;
}
return $data;
}
add_filter( 'affwp_export_get_data_affiliates', 'affwp_custom_export_get_data_affiliates' );