Created
December 20, 2022 21:36
-
-
Save contemplate/36b276c076df548d598c566354f473b6 to your computer and use it in GitHub Desktop.
AffiliateWP: Add WooCommerce Customer Name to Referrals Table & Affiliate Area
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
