Skip to content

@strangerstudios /gist:3137539
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Integrate Paid Memberships Pro with WP Affiliate Platform
<?php
/*
Plugin Name: PMPro WP Affiliate Platform Integration
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-dev/
Description: Process an affiliate via WP Affiliate Platform after a PMPro checkout.
Version: .3
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
IMPORTANT NOTE: The WP Affiliate Platform folks are maintaining a version of this gist that may have important updates. You can get their version here: https://www.tipsandtricks-hq.com/wordpress-affiliate/paid-memberships-pro-wp-affiliate-plugin-integration-873
Both Paid Memberships Pro (http://wordpress.org/extend/plugins/paid-memberships-pro/) and WP Affiliate Platform (http://www.tipsandtricks-hq.com/wordpress-affiliate/) must be installed and activated.
*/
//process affiliate and save id
function wpa_pmpro_after_checkout($user_id)
{
$morder = new MemberOrder();
$morder->getLastMemberOrder($user_id);
if(!empty($morder->total))
{
$sale_amt = $morder->total; //TODO - The commission will be calculated based on this amount
$unique_transaction_id = $morder->code; //TODO - The unique transaction ID for reference
$email = $morder->Email; //TODO - Customer email for record
$referrer = $_COOKIE['ap_id'];
do_action('wp_affiliate_process_cart_commission', array("referrer" => $referrer, "sale_amt" =>$sale_amt, "txn_id"=>$unique_transaction_id, "buyer_email"=>$email));
//save affiliate id in order
$morder->affiliate_id = $referrer;
$morder->saveOrder();
}
}
add_action("pmpro_after_checkout", "wpa_pmpro_after_checkout");
//for new orders (e.g. recurring orders via web hooks) check if a previous affiliate id was used and process
function wpa_pmpro_add_order($morder)
{
if(!empty($morder->total))
{
$sale_amt = $morder->total; //TODO - The commission will be calculated based on this amount
$unique_transaction_id = $morder->code; //TODO - The unique transaction ID for reference
$muser = get_userdata($morder->user_id);
$email = $muser->user_email; //TODO - Customer email for record
//need to get the last order before this
$last_order = new MemberOrder();
$last_order->getLastMemberOrder($morder->user_id);
if(!empty($last_order->affiliate_id))
{
//perform
$referrer = $last_order->affiliate_id;
do_action('wp_affiliate_process_cart_commission', array("referrer" => $referrer, "sale_amt" =>$sale_amt, "txn_id"=>$unique_transaction_id, "buyer_email"=>$email));
//update the affiliate id for this order
global $wpa_pmpro_affiliate_id;
$wpa_pmpro_affiliate_id = $referrer;
}
}
}
add_action("pmpro_add_order", "wpa_pmpro_add_order");
//after the order is saved update the affiliate id column again
function wpa_pmpro_added_order($morder)
{
global $wpa_pmpro_affiliate_id;
if(!empty($wpa_pmpro_affiliate_id))
{
$morder->affiliate_id = $wpa_pmpro_affiliate_id;
$morder->saveOrder();
}
}
add_action("pmpro_added_order", "wpa_pmpro_added_order");
//show affiliate id on orders dashboard page
add_action("pmpro_orders_show_affiliate_ids", "__return_true");
@ladypop2012

Since PMP version has been updated recently to 1.5.9 with fixes and updates to IPN for recurring payments. Can the PMP users get an update to this code for recurring payment use of : Integrate Paid Memberships Pro with WP Affiliate Platform. Thanks

@strangerstudios

I updated the gist to use the order "total" instead of InitialPayment, which should have it working on initial and recurring payments with PMPro version 1.5.9 or higher. Let me know if it doesn't.

@ladypop2012

**DID NOT WORK FOR RECURRING PAYMENT (stripe gateway)** The referring affiliate (AFFtest) was paid for the 1st payment when member JANE registered on 2-07-2013. When STRIPE charged JANE on 3-09-2013 (recurring payment) I looked the backoffice and the referring Affiliate (AFFtest) was NOT paid again.

Note: WP affiliate Platform has a new version and I updated 3 days before the RECURRING payment test to be evaluated. Not sure if something in the new WP affiliate platform change effect something in the strangerstudios code for this integration. Not sure if cookies has any effect on this. But I would like the referring AFFILIATE to be linked to the customer he referred for life. So that anytime the customer buys anything in the future (even if the cookie is expired (over 90 days ) then the affiliate will still get a commission.

*** something I saw on the wp affiliate platform forum ( I think the cookies have everything to do with this im not sure ) read here: http://www.tipsandtricks-hq.com/forum/topic/offering-commissions-for-lifetime-purchases#post-20173

Let me know . P.S Ill be posting this in the paid members support area as well so if it must be a custom solution im open to that so check also in Ill be there to http://www.paidmembershipspro.com/support/

@strangerstudios

Latest revision now has WP plugin comments up top so you can just drop this in the plugins folder. It also should truly support recurring payments by using the pmpro_add_order and pmpro_added_order hooks instead of pmpro_after_checkout and by saving the affiliate id in the orders table and then looking that up from older orders when recurring payments come in.

@ladypop2012

Hello Jason I sent you an email about the outcome, I sent you some screen shots. I need help on this thanks.

@Firefhtr9

Hello,
I just installed WP Affiliate Platform, now I don't know where to install this. I tried downloading it and installing it in my platforms, but it shows the error: The package could not be installed. PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature

I'm sure I'm doing something completely wrong because it doesn't seem anyone else is having this problem. Please help. Thanks.

@seoallrounder

Which file do i have to edit in oder for it to work?

@adventurers73

I just installed WP Affiliate Platform, now I don't know where to install this or what to even do with it! Please help!

@strangerstudios

You guys can sign up for support at http://www.paidmembershipspro.com. Thanks

@Arsenal21

Thank you Jason for creating this integration code.

A few users seem to get confused with what to do with this code. I have created a zip file so you should just need to install that addon plugin:
http://www.tipsandtricks-hq.com/wordpress-affiliate/paid-memberships-pro-wp-affiliate-plugin-integration-873

@suifengtec

Nice codes!

@Arsenal21

Hi, I have made couple of improvements to this addon so it can track recurring commission from paid membership pro also. You can download the updated code from here and update this repository code with it:
http://www.tipsandtricks-hq.com/wordpress-affiliate/paid-memberships-pro-wp-affiliate-plugin-integration-873

@strangerstudios

It looks like the WP Affiliate Platform folks are maintaining a fork of this gist that has some updates. You can grab their copy here: https://www.tipsandtricks-hq.com/wordpress-affiliate/paid-memberships-pro-wp-affiliate-plugin-integration-873

@sepride

Hey, neither this version nor the one on the link you gave yesterday seem to hook into the recurring payments properly. Unsure what is happening. The affiliate id is stored with the subscription orders all right, but the affiliate doesn't get paid when the next month's subscription is billed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.