How to add referrals manually?

โ€”

by

Hey there,

we use Forminator Pro to purchase products with Stripe and PayPal. What is the best way (all programmatically):

1. To get the Affiliate ID and the Campaign ID? (Also for cached sites and also if the pixel is used)
2. To add commissions to an Affiliate?
3. To add a permanent commission to an Affiliate on another purchase? (I also purchased โ€œAffiliates Permanentโ€)
4. To change the calculation based on the success of the affiliate?

################

Based on the explanation on โ€œdocument >> affiliates-enterprise >> api >> referralsโ€:

5. What exactly means โ€œint $post_id (required)โ€?

When a form is sent for purchase, there is a form entry later, but Iโ€™m not sure if it is possible to get the ID in the process.

################

6. How it is possible to add the affiliates role to an existing user? We need to use our own form, cause we need some documents.

Thanks ๐Ÿ™


Comments

20 responses to “How to add referrals manually?”

  1. Hey Bruno,

    You’re welcome, even if I haven’t got an exact ETA, it won’t take long.

    Cheers

  2. Hi again Bruno,

    I had a thorough look at Affiliates Permanent and what we are going to do is prepare an update which will allow you to check for permanent affiliates even via the user email.

    Kind regards,
    George

    1. Hello George, that sounds good. Thank you very much. Do you know approximately when it will be released? I’m sure you know what it’s like, everyone is ready and waiting to get started.

  3. Hey Bruno,

    Please allow me some more time to check if and how you can use permanent assignments in this case. I’ll check the code and let you know.
    As for the campaigns, the campaign ID is calculated within the evaluate method, so there’s no reason for you to make further additions for this part.

    Cheers

  4. Ok, thanks for the clarification. Then I will have to write my own routine and using โ€œadd_referrals()โ€ probably makes more sense as people don’t need to be logged in to place the order. Meaning, yes guest orders are the normal case as there is simply no shopsystem behind it.

    I only have the user’s email during processing.

    I have to manage everything with that. What makes the most sense in your opinion?

    I find the current affiliate with โ€œAffiliates_Service::get_referrer_id()โ€, the campaign with โ€œAffiliates_Service::get_campaign_id()โ€.

    1. how can I pass on the campaign ID so that it records a sale?

    2. how do I get the information whether an affiliate is already assigned to an email and how do I get the ID?

    3. anything else you think I need to be aware of?

  5. Hey Bruno,

    You are right to worry about that since there’s no user data passed in the evaluate method. However, the system will check the referral and adjust the affiliate if there’s a permanent one assigned based on the current user. If this wasn’t possible then we wouldn’t be talking about permanent affiliates in the first place.

    1. Once a customer authenticates or registers, then the system can find out whether there is a permanent assignment or not. Do you also allow guest checkouts/payments?

    2. That’s the typical use case scenario for permanent assignments. You may also check the Affiliates Permanent documentation and especially the description for each one of the settings provided in the plugin’s admin page.

    Kind regards,
    George

  6. And I still hope to get an answer to this question:

    ||ย There is also another important question related to permanent affiliates. You cannot give any customer data to the evaluate( โ€ฆ ) method. How can we check if the customer is already applied to an affiliate if he/she makes another purchase and how can we apply this follow-up purchase to the corresponding affiliate?

    1. This one is handled by Affiliates Permanent and IMO if you also do these checks, then you might end up with another instance of Affiliates Permanent or a conflict.
      Is there a serious reason why you need to follow that path too?

      Cheers

      1. I have no idea whether you don’t understand me or I don’t understand you. When I use the evaluate() function, according to the specifications here, no user data such as email etc. is passed to the function.

        1. how exactly is the system supposed to determine that the new โ€œcustomerโ€ is an existing customer because he has already bought something and is assigned to an affiliate?

        2. if the customer is already assigned to another affiliate and has now come to the site through another affiliate, how can it be ensured that the first affiliate is remunerated because the customer is already assigned to it? And not the new affiliate?

        Cheers

  7. ||ย The role name can be anything you like

    I think you don’t understand me. How can I programmatically assign an existing user as an affiliate ?

    1. Now I see, the affiliate is not a role that’s why I didn’t understand your question in the first place.

      What you need to use is the following:

      Optionally -> !affiliates_user_is_affiliate_status( $user_id, 'pending' );
      Optionally -> !affiliates_user_is_affiliate_status( $user_id, 'deleted' );
      !affiliates_user_is_affiliate( $user_id );

      $userdata = array(
      'first_name' => $user_first_name,
      'last_name' => $user_last_name,
      'user_email' => $user_email
      );
      $status = get_option( 'aff_status', 'active' ); // or 'pending'
      Affiliates_Registration::store_affiliate( $user_id, $userdata, $status = null );

      The first and second lines are optional only if you need to print error messages.

      Then once you check if the user is not already an affiliate, you may proceed and store this new affiliate based on the user’s data I’m mentioning. Once stored, perhaps it would be good if you check the return value, which is int(affiliate id), or bool false.

      Cheers

  8. Hey Bruno,

    You’re welcome. The role name can be anything you like, it doesn’t make any difference and doesn’t affect the Affiliates plugin functionality. The important thing is the capabilities you assign to this role which as you know affects the permissions to your site.

    Kind regards,
    George

  9. There is also another important question related to permanent affiliates. You cannot give any customer data to the evaluate( … ) method. How can we check if the customer is already applied to an affiliate if he/she makes another purchase and how can we apply this follow-up purchase to the corresponding affiliate?

  10. Hello George, thanks for all the infos. Much appreciated ๐Ÿ™

    I know how you can add a role, but what for a role exactly I have to set?

    Role: “Affiliates” ?

    Kind regards

  11. Hey Bruno,

    Please have a look at the arguments description below and also make sure to check the example found in https://docs.itthinx.com/document/affiliates-enterprise/api/referrals/ for the format of $data and $description.


    $amount = bcmul( $form_payment_amount, $your_rate_value, affiliates_get_referral_amount_decimals() ); // we need bcmul here because the value should be a string and the decimals used are determined by the affiliates_get_referral_amount_decimals() unless you wish to use your own amount of decimals.
    $base_amount = null;
    $currency_id = 'USD'; // or if you can retrieve the form payment currency code
    $type = 'form submission'; // or 'sale' or anything indicative for this referral
    $status = // can be one of the following constants AFFILIATES_REFERRAL_STATUS_PENDING or AFFILIATES_REFERRAL_STATUS_ACCEPTED or AFFILIATES_REFERRAL_STATUS_REJECTED

    Also, right at the bottom of the Referrals API page, there is an example implementation of the affiliates_referral action hook, that can be used for post processing referrals.

    Now for the campaign you can use the equivalent Affiliates_Service::get_campaign_id().
    For the cache, I forgot to mention the Troubleshooting section where you can also find possible workarounds for specific cache addons.

    Last but not least, for the role, have you tried the WP methods for adding a role?
    For example,

    wp_update_user( array( 'ID' => $user_id, 'role' => get_role( 'your_existing_role' ) );

    or for a new role

    add_role(
    $new_role,
    __( $new_role ),
    array(
    'read' => true,
    'edit_posts' => true,
    'delete_posts' => false,
    )
    );
    wp_update_user( array( 'ID' => $user_id, 'role' => $new_role );

    Of course this needs to run once the user is registered, via user_register action hook or the equivalent of Forminator, when the registration takes place via a custom form.

    Kind regards,
    George

  12. Since there is no further information, please can you better explain the Parameters from evaluate():

    string $description (optional) default: โ€
    array $data (optional) default: null
    string $base_amount (optional) default: null
    string $amount (optional) default: null
    string $currency_id (optional) default: null
    string $status (optional) default: null
    string $type (optional) default: null

    Thanks

  13. 1.& 2: I checked the method. It seams to return “Affiliates_Service::get_referrer_id()”. But I need also the corresponding campaign ID.

  14. Hello George,

    I don’t use Formidable Forms. As mentioned, I use Forminator Pro: https://wpmudev.com/project/forminator-pro/

    1.& 2: evaluate( … ) sounds good. How can I get access to the corresponding data after the referral is applied? I need this info for our purchase tables for each purchase.

    3. ๐Ÿ‘๐Ÿป

    4. Percentage based on the purchase amount.

    5. Makes sense, thanks.

    6. The role. Affiliates have to fill out a register form, then we create a user from it. Afterwards we creating the user, we need to apply the role to them.

    Kind regards.

    1. Indeed, you mentioned Forminator and while editing my reply for the last time, I read it as Formidable. ๐Ÿ™‚

  15. Hey Bruno,

    Welcome to our support forum and many thanks for using our Affiliates addons on your site.
    Based on your ticket content, I’m assuming that you’re planning to build an integration with Formidable Forms, which is exciting and I would recommend you to have a look at the existing integration we offer here: https://docs.itthinx.com/document/affiliates-enterprise/setup/settings/integrations/formidable/form-referrals-and-leads/

    In the meantime, you may have a look at my replies below ordered according to your questions.

    1.& 2. I think it would be better if you use the evaluate method as described in the API documentation. It will find the applicable affiliate and campaign, so IMO you can avoid these steps. As for the cache, you can first open an affiliate link using a different browser than the one you’re logged into your Dashboard and then check your browser cookies. If you can find the wp_affiliates cookie, the cookie value will contain the affiliate_id followed by the campaign_id if applicable. Otherwise, you need to adjust your cache settings and exclude the affiliate, campaign URL parameters from caching. This also depends on the caching solution you’re running but the main idea is to allow these URL parameters.

    3. Since you already have Affiliates Permanent, you can enable permanent assignments via the plugin settings. You have the option to enable permanent assignments for all your affiliates, or for each individual affiliate. Please have a look at the plugin documentation here -> https://docs.itthinx.com/document/affiliates-permanent/

    4. How do you plan to evaluate an affiliate’s success? Is it based on the count or amount of referrals?

    5. The post_id in this case could have the form entry, or if it’s not possible to retrieve it upon form-submission, then you can only use the form id. Perhaps it might be helpful if you ask their support as well, they might provide a hook when the payment succeeds for a specific form entry.
    6. Is this the WP Role, or you’re looking for a way to make an existing user and affiliate?

    Feel free to ask anything else needed on this matter and we’ll be happy to help you.

    Kind regards,
    George

Share