Skip to content

Instantly share code, notes, and snippets.

@supercleanse
Last active December 20, 2015 00:19
Show Gist options
  • Save supercleanse/6040802 to your computer and use it in GitHub Desktop.
Save supercleanse/6040802 to your computer and use it in GitHub Desktop.
Affiliate Tracking on initial subscription in MemberPress & Affiliate Royale
<?php
add_action('mepr-txn-status-complete', 'mapsn_notification');
function mapsn_notification($txn) {
global $wpdb;
$mepr_db = new MeprDb();
$usr = $txn->user();
$usr_id = $usr->ID;
$txn_count = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*) FROM {$mepr_db->transactions} WHERE user_id=%d AND type=%s AND status=%s",
$usr_id, MeprTransaction::$payment_str, MeprTransaction::$complete_str
)
);
if( $txn_count <= 1 ) {
$wafp_usr = new WafpUser($usr_id);
$ref_id = $wafp_usr->get_referrer();
if(!empty($ref_id) and is_numeric($ref_id)) {
// $ref_id is the user id of the affiliate
// $usr_id is the user id of the customer
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment