How to integrate with WooCommerce

Integrating your WooCommerce-powered WordPress website with Prefinery allows for automatically adding new customers in WooCommerce as new users in Prefinery. Shares and referrals are also automatically tracked, allowing you to setup rewards based on action-based referrals. 

To integrate Prefinery with your WooCommerce-powered WordPress website, you'll need to have a dedicated thank-you page which includes the user's email address. This thank-you page must be set so that after the user completes your checkout process, they get redirected to this page. 

There are a number of WooCommerce thank-you page options out there from paid extensions to plugins, but for this tutorial we'll make use of the free version of NextMove Lite - Thank You Page for WooCommerce to automatically setup a thank-you page for your WooCommerce store. 

Note: This guide assumes WooCommerce is already setup on your WordPress website. 

1

[Optional] If you want to set up a reward in Prefinery that requires a person to refer friends AND that those friends make a purchase, then create the reward in Prefinery and be sure to set the Award Event to Custom Event with the word "purchase" as the Award Event Name. 

Check out our help guide on triggering rewards with a custom event for more information on how this works.

2

To install the Prefinery JavaScript Snippet on your WordPress website, follow steps 1 to 4 of our guide here: How to Install the Signup Form on Wordpress

3

[Optional] If you already have a thank-you page setup for your WooCommerce store, skip this step. Otherwise do as follows: 

Go to Plugins > Add New and search for "woocommerce thank you" or "nextmove woocommerce". You should find NextMove Lite - Thank You Page for WooCommerce in the results. Install the plugin then Activate it.

Once activated, the plugin will autosetup the Thank You page and redirect you to the WooCommerce Settings page. Under the NextMove Lite: XLPlugins tab, find the Thank You page in the list then Edit it. 

4

You'll use Prefinery's JavaScript Web API in order to add new WooCommerce customers as new users in your Prefinery campaign. Depending on your use case, you can use one of the following JavaScript code snippets: 

A. If you just want to add the customer to Prefinery after they make a purchase: 

<script type="text/javascript">
  var search_in = document.body.innerHTML;
  string_context = search_in.toString();
  array_mails = string_context.match(/([\+a-zA-Z0-9/._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
  var email = array_mails[0];
  // Add the person to your Prefinery campaign
  prefinery('addUser', email);
</script>

The above code will add new customers to Prefinery, and track all shares and referrals through their referral link. See example #1 of our JavaScript Web API tutorials for more details. 

B. If you set up a reward as described in step 1, such that the customer's referral, after performing a custom action (e.g. "purchase"), also counts towards - and can trigger - a reward for their referrer, use this instead: 

<script type="text/javascript">
  var search_in = document.body.innerHTML;
  string_context = search_in.toString();
  array_mails = string_context.match(/([\+a-zA-Z0-9/._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
  var email = array_mails[0];
  // Add the person to your Prefinery campaign
  prefinery('addUser', email, function(user) {
    // Record the user performed the 'purchase' event
    prefinery('triggerRewards', {
      email: user.email,
      event: 'purchase',
    });
  });
</script>

The above code will add new customers to Prefinery, record that they did the custom event "purchase", and track all shares and referrals through their referral link. See example #2 of our JavaScript Web API tutorials for more details. 

Copy either of the above code snippets you want to use and while editing your thank-you page in WordPress, switch from the Visual editor view to Text (or HTML) view, in a new line at the bottom of the content box paste in your copied script, then save your changes by clicking on the Update button. 

That's it!

Still need help? How can we help? How can we help?