Skip to content

Instantly share code, notes, and snippets.

@codelion7
Last active October 25, 2018 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codelion7/e6ed58e5d97514583b807b3f95e46df9 to your computer and use it in GitHub Desktop.
Save codelion7/e6ed58e5d97514583b807b3f95e46df9 to your computer and use it in GitHub Desktop.
Add Parent Affiliate Column to Referrals Export
<?php
/**
* Add new column to the exported referrals CSV file for the affiliate's Parent
*/
function affwp_mlm_export_referrals_csv_cols( $cols ) {
$cols['parent_name'] = 'Parent Affiliate';
return $cols;
}
add_filter( 'affwp_export_csv_cols_referrals', 'affwp_mlm_export_referrals_csv_cols' );
/**
* Add the the affiliate's Parent to our new csv column
*/
function affwp_mlm_export_get_data_referrals( $data ) {
foreach ( $data as $key => $d ) {
$affiliate_id = $data[$key]['affiliate_id'];
$parent_id = affwp_mlm_get_parent_affiliate( $affiliate_id );
$parent_name = ( ! empty( $parent_id ) ) ? affiliate_wp()->affiliates->get_affiliate_name( $parent_id ) : 'None';
$data[$key]['parent_name'] = $parent_name;
}
return $data;
}
add_filter( 'affwp_export_get_data_referrals', 'affwp_mlm_export_get_data_referrals' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment