Your cart is currently empty!
Stop crediting affiliates after a year
—
by
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
Comments
5 responses to “Stop crediting affiliates after a year”
You’re welcome Huaqing, hope you enjoy the plugin and your project in general.
Cheers,
George
Hi George,
This is extremely helpful, even before I asked! Thank you so much!
Best regards,
Huaqing
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
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
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