Last active
December 20, 2015 00:19
-
-
Save supercleanse/6040802 to your computer and use it in GitHub Desktop.
Affiliate Tracking on initial subscription in MemberPress & Affiliate Royale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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