Ninja Forms

Ninja Forms 3.0 or higher

Ninja Forms 3.0 and higher is supported.

Initial setup

  1. Ensure AffiliateWP version 1.9+ is installed and activated.
  2. Ensure Ninja Forms version 3.0+ is installed and activated.
  3. To enable integration with Ninja Forms, go to Affiliates → Settings → Integrations and check the box next to Ninja Forms. Click Save Changes
  4. In the WordPress admin menu, go to Forms and click the Add New button.
  5. Click on the “Just click here and select the fields you want.” link to start building your form. Add at least a couple of fields (for example, First Name and Email).
  6. You will also be required to add a Submit button.
  7. To enable referrals to be generated for this form, go to the Emails & Actions tab. Click the Plus (+) icon in the bottom right corner of the page.
  8. Click the Add Referral option under the Installed section. This will add a new Action called "Add Referral" to the form. New "Add Referral" action added:
  9. When the Add Referral action has been added, your form will now generate $0.00 referrals for affiliates who refer form submissions.  If this is OK for your setup, you are finished!  
  10. If you would like AffiliateWP to calculate a specific referral amount for each form submission, or set a specific referral Description or Referral Type (Sale, Opt-in, or Lead), click on the cog icon next to Add Referral to edit the action. You'll see some new options appear on the right-hand side of the page.  

    Ninja Forms actions add referral
  11. NOTE: As of Ninja Forms version 3.4.6, the pre-defined Product and Total fields are no longer available. That said, you can use any field you create to store this information if desired, and then use the Calculation action to determine a final total to assign in the TOTAL FIELD on the Add Referral action. That total will be used in the referral amount calculation as before.
  12. To calculate a specific referral amount for each submission (using a referral rate type of percentage), you will need to add optional fields to store values such as quantity and pricing if you'd like the user to select/set these values before submitting the form.   You can name these fields whatever you like.
  13. To perform a calculation, Use the Advanced - Calculations action to perform any multiplication, addition, etc. to come up with a total. Helpful video tutorial on how to use the Calculations feature in Ninja Forms:
  14. Screen Shot 2019-08-29 at 15 13 37

    Otherwise, you can place a single numeric value in a field of your choice to be used for the final referral calculation in the next

  15. AffiliateWP will use the global Referral Rate and Referral Rate Type (as set in Affiliates → Settings → General) to calculate an affiliate commission based on the amount you enter in the TOTAL FIELD above.

    Example of setting a Flat Rate referral rate: If Ninja Forms is your only integration with AffiliateWP and you wish to generate a $2.00 affiliate commission for a form submission, you could enter a Flat Rate of “2" in AffiliateWP’s General settings. Now, when an affiliate refers a visitor, and the visitor completes and submits this form, a commission of $2.00 will be generated for the affiliate and there isn't a need for setting a total amount.

    Example of setting a Percentage referral rate: If you wish to use a Percentage referral rate type (e.g. you have multiple integrations and/or forms, or you would prefer to work with percentages), and you wish to generate a $5.00 affiliate commission on every submission of this particular form, you could set a global Referral Rate of 20% in AffiliateWP's General settings, and enter “25.00" in the field you are using as your TOTAL FIELD assignment you'll set below. When an affiliate successfully refers a visitor, and the visitor completes and submits this form, a commission of $5.00 will be generated for the affiliate.

Final steps: Mapping the form with merge tags

If you have set up your form to calculate a specific referral rate based on final total amount field, follow the steps below.

  1. Click on the click on the cog icon next to Add Referral to edit the action. You'll see some new options appear on the right-hand side of the page.
  2. In the Total field, click on the menu icon. Select the corresponding merge tag from your form. As per the below example, the merge field tag is Total, but the field can be named whatever you like. 

  3. For any other fields in your form, click on the menu icon. Select the corresponding merge tag from your form. As per the below example, we've merged the email field in the form with the Email merge tag. Repeat this step as necessary to map your form.
  4. In the Description field, enter some text that clearly describes where the referral came from, such as “My Contact Form” or “My First Product”, etc.
  5. Click the Done button.
  6. Click the Publish button.
  7. If you haven’t already given your form a title, you'll be prompted to do so. Give your form a title and click Publish again.
Your form is now ready to insert on any page or in any post! Now, when an affiliate refers someone to your site, and that person completes this form, the affiliate will be awarded a commission based on what you have set in the form and/or AffiliateWP’s General settings.

Older versions of Ninja Forms

From version 1.7 onwards, you can now enable and disable referrals on  any Ninja Form. Once the integration has been enabled:

  1. Go to the Settings tab of your form
  2. Open the Restrictions section
  3. Enable the Allow Referrals checkbox
  4. Click Save

Once enabled, AffiliateWP will automatically generate a referral each time the customer is referred by an affiliate and submits a form.

In Affiliates → Referrals, the Reference;column refers to the entry ID in Ninja Forms:

Clicking on the  Reference column will take you directly to the entry details page in Ninja Forms.

That's it, you're done!

The old, old method

Note: Prior to version 1.6, Ninja Forms was only minimally supported. The old integration method is described below for reference or if you need to use it for any reason. If you use the method below, leave the  Ninja Forms box unchecked in Affiliates → Settings → Integrations.

This document will walk you through how to setup simple referral tracking with Ninja Forms. It uses the same function that the [affiliate_conversion_script] shortcode uses and demonstrates how you can pass dynamic values into the function.

Most of the code shown below can be used to help you set up dynamic values for any other form plugin or system that you are using.

First, set up your Ninja Form with the fields you require. The total field is optional and if you choose not to have it, the referrals will simply be created with a zero value.


If you are wanting the amount to be calculated in the referral, take note of the Field ID for your total field:


And this is what the form looks like on the front-end:


Second, set up the form to redirect to another page upon submission. You can configure this option under the Notifications tab. This will be the page that users land on after submitting the form.


Third, copy and paste the following code (mind the opening PHP tags) into your child theme's functions.php or custom plugin. If you're using a total field, replace the $total_field_id variable below with the Field ID of your total field (shown in the second image above).

That's it! When a referral link is used and the customer fills out your Ninja form, a new referral will be created.