Stop crediting affiliates after a year

I only want to credit affiliates on every purchase brought by referred customers for 1 year. Is it possible unassign the customer from the associated affiliate automatically 1 year after the 1st order is purchased?

If it cannot be configured out-of-box, can you explain how itcan be done programatically? Any filter/hook we can use?

In this topic, it seems that we can remove the relationship of an user to an affiliate in wp_aff_affiliates_users to unassign the user. Is that correct?

Is the first referral time recorded in any table? We are considering using the first order placing time for each user if it is not recorded.

What’s the filter/hook that an affiliate commission is calculated or assigned? Is that good place to detect the expiration and remove the relationship?

Thanks,
Kooyaya

5 Responses to Stop crediting affiliates after a year

  1. George July 30, 2020 at 12:23 pm #

    You’re welcome Huaqing, hope you enjoy the plugin and your project in general.

    Cheers,
    George

  2. huaqing bao July 29, 2020 at 4:54 am #

    Hi George,

    This is extremely helpful, even before I asked! Thank you so much!

    Best regards,
    Huaqing

  3. George July 28, 2020 at 1:26 pm #

    Hu Huaqing,

    Please have a look at the WordPress documentation on scheduled tasks if you’re not familiar with the subject. The link attached goes to the official WP documentation and apart from that you will find tons of resources on the internet for this matter.

    Kind regards,
    George

  4. huaqing bao July 28, 2020 at 3:36 am #

    Hi George,

    Thank you so much for your helpful suggestion! I will give it a try.

    Can I run this query in a scheduled task to find out first referral time for each user:
    SELECT user_id, MIN(datetime) FROM wp_aff_referrals
    GROUP BY user_id

    Best regards,
    Huaqing

  5. George July 27, 2020 at 4:58 pm #

    Hi Huaqing,

    FYI, what you described here is a pretty unique case which can only be covered with a custom implementation.
    For this, you should first find when was the first referral recorded for each affiliate, then compare this date with the current date and finally remove the usermeta permanent assignment with
    delete_user_meta( $user_id, 'permanent_referrer_affiliate_id' );

    You can find the date of each referral in wp_aff_referrals table but the tricky part here is to locate the first referral. What I would do is check each recorded referral using affiliates_referral action hook and add a usermeta flag/date field to indicate the first referral for each affiliate. Then using scheduled tasks you need to create expiration tasks -one for each affiliate- and remove the permanent affiliate id after one year.

    Kind regards,
    George

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

AffiliatesContactJobsTerms & ConditionsPrivacy PolicyDocumentationDownloadsUseful PluginsMy Account

Share