Is there an API function call to get top tier affiliate ID?

Thanks to @antonio I’m now able to display affiliate info to the visitor and even pass the info to custom order data fields in woocommerce so an order now contains the referrer information!

There’s one data field I cannot figure out how to get though.

I’m implementing my 2-level affiliate tier system such that level one represents a Group, if you will, and level 2 represents the individual Sellers in that Group. Therefore, I want to be able to display the following info to the visitor on checkout: 1) the Group’s name (tier 1) and 2) the Seller’s name (tier 2 if it exists).

I just cannot figure out how to get the tier 1 (referred by) ID, given a tier 2 (or 3 or 4 …) ID. I would really appreciate seeing some code that would allow me to do this : )

Thanks guys!

-Regis

One Response to Is there an API function call to get top tier affiliate ID?

  1. kento March 3, 2014 at 3:01 pm #

    For the downline there is an API function* but not (yet) for the upline, so this would have to be done in the following way, assuming that you have the ID of the affiliate who’s referrer you would like to obtain in $affiliate_id :

    global $affiliates_db;
    $affiliates_relations_table = $affiliates_db->get_tablename( 'affiliates_relations' );
    $referrer_id = $affiliates_db->get_value( "SELECT from_affiliate_id FROM $affiliates_relations_table WHERE to_affiliate_id = %d", intval( $affiliate_id ) );

    The referring affiliate’s ID would then be available in $referrer_id if that affiliate was referred.

    * For the downline Affiliates_Multi_Tier::get_tree( array( $affiliate_id ), $tree ); where $tree will contain the resulting downline for the given affiliate.

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share