I’m building out a new website for my core product ThirstyAffiliates at the moment and as part of the process we’re moving the affiliate program internal (I’ll be sending out an email about this shortly to my affiliates).
Previously it was run as part of my e-junkie shopping cart, but I made the executive decision to bring the shopping cart experience back home and that means I will lose my built in affiliate program that I had with them.
Don’t get me wrong I still love their shopping cart and actively recommend it. It’s a very light and effective tool for selling a limited number of products and I’m actually still using it for my other product Simple Page Tester. But there’s some bigger things afoot with ThirstyAffiliates which means it wasn’t practical to use this time (more on that in another post soon, I promise).
Anyhow, I stumbled onto a neat plugin called Affiliates which lets you run an affiliate program very effectively from your WordPress website and it has a bunch of handy integrations with various WordPress shopping carts freely available (I’m using the WooCommerce one).
I did run into one hitch though and I posted a comment on the Affiliates website recently asking if it was possible to do a tiered commission structure in the Pro version and if so I’d upgrade happily from the free version.
To my great surprise Antonio replied less than 3 hours later and informed me that it was indeed possible and that I wouldn’t even need to upgrade to Pro to do it. Edit: My mistake, you do actually need to upgrade to Pro, but it’s a steal at $59 and you get a lot more features including another one I was after for importing users from my existing program.
He proceeded to give me the following code snippet (which I modified a little bit):
class MyCustomReferralMethod { /** * Registers a custom referral amount method. */ public static function init() { if (class_exists('Affiliates_Referral')) { Affiliates_Referral::register_referral_amount_method(array(__CLASS__, 'setCommissionTiers')); } } /** * Custom referral amount method implementation. * @param int $affiliate_id * @param array $parameters */ public static function setCommissionTiers( $affiliate_id = null, $parameters = null ) { $result = '0'; if (isset($parameters['post_id'])) { $affiliate_id = $parameters['affiliate_ids'][0]; $referrals = affiliates_get_affiliate_referrals($affiliate_id); if ($referrals < 10) { $commission = 0.3; } else if ($referrals < 20) { $commission = 0.4; } else { $commission = 0.5; } $result = bcmul($commission, $parameters['base_amount'], 2); } return $result; } } add_action('init', array('MyCustomReferralMethod', 'init')); |
Just drop that bad boy right into your functions.php file in your theme.
The tiered affiliate commission structure I wanted was:
- 1-9 sales: Your commission rate is 30%
- 10-19 sales: Your commission rate is 40%
- 20+ sales: Your commission rate is 50%
If you’re selling a product and want to setup an affiliate program in-house like me on your WordPress based website I suggest you check out the Affiliates plugin (I’m using the WooCommerce Pro Integration version).
You can use the above code to do something similar if you like and if you need to adjust any of those numbers just play with the $commission variable in that hairy looking IF statement (0.3 = 30%) and the boundaries for the $referrals variable to adjust the number of sales.
Hope you enjoy the snippet.