Skip to content

Instantly share code, notes, and snippets.

@contemplate
Created December 20, 2022 21:36
Show Gist options
  • Save contemplate/36b276c076df548d598c566354f473b6 to your computer and use it in GitHub Desktop.
Save contemplate/36b276c076df548d598c566354f473b6 to your computer and use it in GitHub Desktop.
AffiliateWP: Add WooCommerce Customer Name to Referrals Table & Affiliate Area
/**
* Add customer name to reference column of the referrals page
*/
function affwp_custom_wc_referrals_user_link( $reference, $referral ) {
if ( ! ( 'woocommerce' == $referral->context || class_exists( 'WC_Order' ) ) ) {
return $reference;
}
$order = wc_get_order( $referral->reference );
if( ! $order ){
return $reference;
}
$customer_first_name = ( $order->get_billing_first_name() ) ? $order->get_billing_first_name() : '';
$customer_last_name = ( $order->get_billing_last_name() ) ? $order->get_billing_last_name() : '';
if ( $customer_first_name ) {
return $reference . ' - ' . $customer_first_name . ' ' . $customer_last_name;
}
return $reference;
}
add_filter( 'affwp_referral_reference_column', 'affwp_custom_wc_referrals_user_link', 10, 2 ); //add to reference
//add_filter( 'affwp_referral_table_description', 'affwp_custom_wc_referrals_user_link', 10, 2 ); //add to description
/**
* Add customer name to reference column of the referral exports
*/
function affwp_referral_export_get_data_line_customer( $fields, $referral ) {
if ( ! ( 'woocommerce' == $referral->context || class_exists( 'WC_Order' ) ) ) {
return $fields;
}
$order = wc_get_order( $referral->reference );
if( ! $order ){
return $fields;
}
$customer_first_name = ( $order->get_billing_first_name() ) ? $order->get_billing_first_name() : '';
$customer_last_name = ( $order->get_billing_last_name() ) ? $order->get_billing_last_name() : '';
if ( $customer_first_name ) {
$fields['reference'] = $fields['reference'] . ' - ' . $customer_first_name . ' ' . $customer_last_name;
}
return $fields;
}
add_filter( 'affwp_referral_export_get_data_line', 'affwp_referral_export_get_data_line_customer', 10, 2 ); //add to reference
/**
* Add Customer Colum to Affiliate Area Refferals Tab
*/
function affwp_referrals_dashboard_th_customer() {
echo'<th class="referral-customer">Customer</th>';
}
add_action( 'affwp_referrals_dashboard_th', 'affwp_referrals_dashboard_th_customer' );
function affwp_referrals_dashboard_td_customer($referral) {
$order = wc_get_order( $referral->reference );
if( ! $order ){
return $reference;
}
$customer_first_name = ( $order->get_billing_first_name() ) ? $order->get_billing_first_name() : '';
$customer_last_name = ( $order->get_billing_last_name() ) ? $order->get_billing_last_name() : '';
echo'<td class="referral-customer" data-th="Customer">'. $customer_first_name . ' ' . $customer_last_name .'</td>';
}
add_action( 'affwp_referrals_dashboard_td', 'affwp_referrals_dashboard_td_customer' );
@contemplate
Copy link
Author

Adds Customer Name ( from WooCommerce ) to the following Referral Tables:

  • Admin Referrals Table
  • Referrals Export
  • Affiliate Area Referrals Table

@viraniglobal
Copy link

Hello

Let me know where should I add this code in my wordpress plugin.

Thank you in advance.

@contemplate
Copy link
Author

@viraniglobal you can add this code to your Child Theme's functions.php file or use the Code Snippets plugin ( https://wordpress.org/plugins/code-snippets/ ) and add this as a new snippet to your site.

@viraniglobal
Copy link

Thank you for your confirmation. Please check the following link it showing blank...Can you help me for the same. Also let me know if we can add email also in next column.

Looking forward to your support.
Dashboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment