Get Affiliate ID of viewed user

Posted in

Hi there,

How can I retrieve the affiliate ID of the user currently being viewed?

7 Responses to Get Affiliate ID of viewed user

  1. Rudi July 21, 2016 at 4:59 pm #

    Thanks so much, that works a treat! 😀

    Much appreciated!!

    • antonio July 22, 2016 at 5:46 pm #

      Perfect 🙂

  2. Rudi July 20, 2016 at 7:15 pm #

    Hi Antonio,

    Thanks for your help so far. I have a page which lists all the users on the site. Using the shortcode, it echos “2” as Afilliate ID for every user, which is the affiliate ID of my admin account (thus the logged in user ID).

    • antonio July 21, 2016 at 7:41 am #

      Hi Rudi,
      Ok, you can use the Affiliates API to create your how solution.
      I have created this shortcode. If you add this code in your functions.php theme file, it should work:

      add_shortcode( 'affiliates_affiliate_id_by_user', 'my_affiliates_affiliate_id_by_user' );
      function my_affiliates_affiliate_id_by_user ($atts, $content = null ) {
      $output = "";
      $options = shortcode_atts(
      array(
      'id' => null
      ),
      $atts
      );
      extract( $options );
      if ( $id !== null ) {
      if ( affiliates_user_is_affiliate( $id ) ) {
      $affiliate_ids = affiliates_get_user_affiliate( $id );
      if ( ( $affiliate_ids ) && ( sizeof( $affiliate_ids ) > 0 ) ) {
      $output .= $affiliate_ids[0];
      }
      }
      }
      return $output;
      }

      If the user id is 25, the use is: [affiliates_affiliate_id_by_user id="25" /]
      Kind Regards,
      Antonio B.

  3. Rudi July 20, 2016 at 8:21 am #

    Hi there Antonio.

    That returns the ID of the logged in user. I need to retrieve the ID of the user being viewed (ie, to generate a custom table which includes the unique referral codes of each user).

    Kind regards,
    Rudi

    • antonio July 20, 2016 at 5:55 pm #

      Hi Rudi,
      The [affiliates_id] shortcode display the current affiliate’s ID, not the ID of the logged in user.
      Really I don’t know exactly what do you want to do. Please give us more information. Remember that from Affiliates->Manager Affiliates you can see the affiliate IDs and their urls.
      Kind Regards,
      Antonio B.

  4. antonio July 19, 2016 at 10:49 pm #

    Hi Rudi,
    you can use the [affiliates_id] shortcode.
    Kind Regards,
    Antonio B.

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