Differentiate different “Sale” referrals

Hi guys,

We’re improving the Affiliate Stats shortcode and we would like to differentiate different type of “sale” referrals.

To be more precise, we’d like to add something in the [data] key of the variable $IXAP15 (in “class-affiliates-affiliate-stats-renderer-wordpress.php”) when the referral was made through a permanent association.

Currently, there are no information I can use to differentiate a referral that originates directly from the affiliate’s marketing efforts and a referral that originates from an associated user.

I’ve taken a look inside “affiliates-products/lib/comp/class-affiliates-products-woocommerce.php” and I thought I found the $data variable that is used when storing the referral. I added an element to the array there so that I could trace back that line. Unfortunately, even with the modified code I couldn’t find back the “PERMREF” string I was looking for :


Could you let me know where I can add some code to add information in the [data] key for referrals triggered by permanent association?

The purpose of this modification is to inform affiliates when a referral came directly from their marketing efforts or if it was triggered from an association that could’ve taken place a while ago. It gives more elements to appreciate the passive revenue generated by the permanent association system.

Thank you!

Kind regards,



Whoa! After a few hours of trial and errors I managed to further improve the Affiliate Stats shortcode and add the information I wanted.

I had to edit a couple of files

wp-init.php in “/affiliates-enterprise/lib/core”

Added the function “affiliates_get_user_affiliate_relations( $affiliate_id )” to return the affiliate IDs related to an affiliate. Based on “affiliates_get_user_affiliate”

* Return the affiliate ids related to an affiliate.
* @param int $affiliate_id
* @return array of int affiliate ids or null on failure
function affiliates_get_user_affiliate_relations( $affiliate_id ) {
global $wpdb;
$result = null;
$affiliates_table = _affiliates_get_tablename( 'affiliates' );
$affiliates_relations_table = _affiliates_get_tablename( 'affiliates_relations' );
if ( $affiliates = $wpdb->get_results( $wpdb->prepare(
"SELECT $affiliates_table.affiliate_id FROM $affiliates_relations_table LEFT JOIN $affiliates_table ON $affiliates_relations_table.to_affiliate_id = $affiliates_table.affiliate_id WHERE $affiliates_relations_table.from_affiliate_id = %d AND $affiliates_table.status ='active'",
intval( $affiliate_id )
) ) ) {
$result = array();
foreach( $affiliates as $affiliate ) {
$result[] = $affiliate->affiliate_id;
return $result;

class-affiliates-permanent.php in “/affiliates-permanent”

Changed the function “get_referrer” from PRIVATE to PUBLIC to be able to use it in affiliates-woocommerce.php

affiliates-woocommerce.php in “/affiliates-woocommerce”

Added a check for Affiliates_Permanent to add some data to the referral object if it is associated with a permanent referrer

if (class_exists('Affiliates_Permanent')) {
$order_user_id = get_post_meta( $IXAPWO6, '_customer_user', true );
$referrer_id = Affiliates_Permanent::get_referrer( $order_user_id );
if($referrer_id) {
$IXAPWO102[] = array(
'referrer_id' => array(
'title' => 'Referrer ID',
'value' => esc_sql( $referrer_id )
} else {
$IXAPWO102[] = array(
'referrer_id' => array(
'title' => 'Referrer ID',
'value' => 'NOREF'

class-affiliates-affiliate-stats-renderer-wordpress.php in “/affiliates-enterprise/lib/ext/wordpress”

Important modification of the Affiliate_Stats shortcode to display detailed information about referrals.

Currently displays :
-> Manual referrals (Affiliates)
-> Direct sale (Affiliates)
-> Multi-tiered sale (Affiliates Enterprise)
-> Linked product sale (Affiliates Product)
-> Permanent association of a new user to the affiliate (Affiliates Permanent)

All other situations return N/A. I plan to add some more conditionals to cover…
-> Detailed tiers information
-> Referrals through forms (will only do Formidable since we don’t use)
-> Subscription referrals
-> The other situations I haven’t covered yet and I’m not thinking of 😉

Hopefully you can take some ideas from this to include in future releases. Maybe don’t scrape the affiliate_stats shortcode but write a different one, more flexible, inspired by what I did here. There would be some things to work on before my modifications can make it to a release (localize the strings to change them/translate them, add options to enable/disable some actions from being displayed).

Additionally, I’d like the order_meta for each items to be available through a +/- button when applicable. This would make a decent detailed referral overview. Although it might take some time before we get there hehe…

That’s it!

I’ll update the ticket if there’s some news.

PS : George has an admin access to our platform if you want to check the files, or I can also send you the files I modified.

Kind regards,

4 Responses to Differentiate different “Sale” referrals

  1. Bastien January 19, 2016 at 10:00 pm #

    (I could’ve added the function in our child theme’s functions.php and wrap it in an IF conditional too I guess, it probably makes more sense, not sure why I absolutely wanted to put that in the plugin file hehe)

  2. Bastien January 19, 2016 at 9:55 pm #

    Hey Kento!

    Thanks a lot for adding these filters, it’s indeed quite easier to manage the shortcode content this way.

    All I had to do was to add the function in wp-init again but other than that everything worked like a charm when I imported our code.

    Have a great day!

    Kind regards,

    • Kento January 20, 2016 at 12:40 pm #

      Perfect! Have a great day, too! 🙂

  3. Kento January 18, 2016 at 9:52 am #

    Hi Bastien,

    Many thanks for the suggestions and code ideas, that’s a great contribution!

    With the new filters introduced in 2.14.1 and based on the Affiliates Stats Filters Example you should now be able to include your data without the need to modify the plugin files. Also thanks for the suggestion of the additional function, I would recommend to enclose it in a if (!function_exists('...')) as we might be including it.


We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account