Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
AffiliateWP - Add the customer's first name, last name and email who the affiliate referred as columns in the exported referrals .csv file
<?php
/**
* Add new columns to the exported referrals CSV file for the customer's first name, last name and email address
*/
function affwp_custom_export_referrals_csv_cols( $cols ) {
$cols['customer_first_name'] = 'Customer First Name';
$cols['customer_last_name'] = 'Customer Last Name';
$cols['customer_email'] = 'Customer Email';
return $cols;
}
add_filter( 'affwp_export_csv_cols_referrals', 'affwp_custom_export_referrals_csv_cols' );
/**
* Add the customer's first name, last name and email address to our new csv columns
*/
function affwp_custom_export_get_data_referrals( $data ) {
foreach ( $data as $key => $d ) {
// get EDD payment user info
$payment_user_info = edd_get_payment_meta_user_info( $data[$key]['reference'] );
$customer_first_name = isset( $payment_user_info['first_name'] ) ? $payment_user_info['first_name'] : '';
$customer_last_name = isset( $payment_user_info['last_name'] ) ? $payment_user_info['last_name'] : '';
$customer_email = isset( $payment_user_info['email'] ) ? $payment_user_info['email'] : '';
$data[$key]['customer_first_name'] = $customer_first_name;
$data[$key]['customer_last_name'] = $customer_last_name;
$data[$key]['customer_email'] = $customer_email;
}
return $data;
}
add_filter( 'affwp_export_get_data_referrals', 'affwp_custom_export_get_data_referrals' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment