Affiliates and MarketPress

Greetings. I found a good amount of discussions over integrating the Affiliates plugin with the MarketPress plugin, but none with definite solutions. Moreover, there doesn’t seem to be any documentation to help us create an Affiliates plugin addon to accomodate.

Barry (in this post) mentions that it is quite easy to hook in and extend, but doesn’t say how or which methods are needed. Is there any documentation online to identify where the Affiliate plugin should hook into MarketPress in order to get started on paying affiliate commissions based on sales? I understand that Affiliates plugin “listens” or “watches” activity. I guess I need to know what activities I should be watching in order to add Affiliate commission. Barry said it could be done “with a single line of code.” I am willing to take a stab at this since I need it working immediately. If it does not, I’ll have to reach out to another service.

Thanks for the discussions and help, everyone. I hope to get this working soon.

  • DavidM
    • DEV MAN’s Mascot

    Hi resolutecreative and first off, welcome to WPMU DEV!

    Let me see if I can get Barry’s attention on this thread. Is there a reference to the “single line of code” you mentioned though? I couldn’t seem to find that in the thread you linked to but if you’ve noticed that somewhere, I can have a look and see about clarifying it.



  • resolutecreative
    • New Recruit

    Thanks DavidM for helping. I really need to resolve this today if it is possible.

    The reference to Barry’s response was in his comment quoted below:

    yep we have a lot of actions and hooks that can be hit (in fact you can pretty much add as many clicks, referrals, purchases, credits and debits as you want on our plugin with a single line of code), we also have an add-ons capability so that the affiliate plugin can be extended – however there also needs to be relevant hooks and filters in the plugins that you want to integrate with in order for the two to communicate with each other via the add-on.


  • Mason
    • DEV MAN’s Sidekick


    As we haven’t heard back from you we’re going to assume the problem was sorted out and mark this ticket as resolved.

    If it wasn’t resolved, or you have any more questions related to this thread please feel free to post them below and tick the ‘Mark as Not Resolved (re-open)’ box below the post area (or else we’ll miss it!)

    Otherwise, thanks for using the forums, and for being a member of WPMU DEV, it’s a pleasure to help you out and we look forward to being of assistance in the future.


  • resolutecreative
    • New Recruit

    This is from memory.

    (MarketPress) paypal-express.php, line 478

    function order_confirmation($order) {
    global $wpdb;
    global $affiliate;

    // we don't need to do anything unless there is an affiliate cookie
    if(isset( $_COOKIE['affiliate_' . COOKIEHASH])) {
    // Get the cookie hash so we know who the referrer is
    $hash = addslashes($_COOKIE['affiliate_' . COOKIEHASH]);

    $db =& $wpdb;
    $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'affiliate_hash' AND meta_value = %s", $hash) );

    // if we found the affiliate's user_id, then give them commission
    if ($user_id > 0) {
    $commissionRate = 5.00; // everyone gets 5.00 per item
    $numberItems = $order->mp_order_items;
    $commissionAmount = number_format($numberItems * $commissionRate);

    $affiliate->record_credit($user_id, $commissionAmount);

    (Affiliate) affiliateadmin.php, line 1283

    $sql = $this->db->prepare( "INSERT INTO {$this->affiliatedata} (user_id, period, payments, lastupdated) VALUES (%d, %s, %01.2f, now()) ON DUPLICATE KEY UPDATE payments = payments + %f", $user_id, $period, $payment, $payment );

    (Affiliate) affiliateadmin.php, line 1804

    if(count($affdetails) == 2) {
    $affected = $this->db->query( "UPDATE " . $this->affiliatedata . " SET payments = payments + (credits - debits), credits=0, debits=0, lastupdated = '" . current_time('mysql', true) . "' WHERE user_id = " . $affdetails[0] . " AND period = '" . $affdetails[1] . "'" );

    (Affiliate) affiliateadmin.php, line 1821

    $affected = $this->db->query( "UPDATE " . $this->affiliatedata . " SET payments = payments + (credits - debits), credits=0, debits=0, lastupdated = '" . current_time('mysql', true) . "' WHERE user_id = " . $affdetails[0] . " AND period = '" . $affdetails[1] . "'" );

  • aecnu
    • WP Unicorn

    Greetings Folks,

    Sorry that I cannot confirm of the success of the above coding for you and though Barry has been flagged on this, it is obvious that it will take a concerted effort with the Market Press plugin lead developer to get it implemented.

    The Market Press lead developer is on vacation until the 10th of July so it appears that no action will be taken before that time at the very earliest.

    Thank you all for being WPMU Dev Members!

    Cheers, Joe

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.