How to Track Affiliate / Referral Sales in WP e-Commerce Shopping Cart Plugin for WordPress

I’ve been using the WP e-Commerce Shopping Cart plugin for WordPress for a few years now. Unfortunately there isn’t much in the way of affiliate or referral plugins for WP e-Commerce. I’ve been on the lookout for an easy solution to track referral sales. I didn’t need something as complex as most affiliate management systems. I decided to have a try at creating an easy solution for tracking referral sales. I ended up with a fairly simple solution, which requires just one modification to your shopping cart theme. It works in conjunction with the “Cookie Monster” plugin.

How it works

First, I’ll explain how this will work so you know what you’re getting into. We’re going to use the Cookie Monster plugin to allow us to capture a cookie based on the URL the visitor uses to enter your website (i.e. http://www.yourstore.com?ref=JohnDoe). The cookie will now be remembered (in this case “JohnDoe”) and stored in the users browser. At checkout the cookie is passed on via a hidden field “how_find_us” which is normally used to determine how the customer found your site (but we’ll be modifying that).

The way this will work for your affiliates is they’ll need to choose an affiliate code, anything really, such as “Bob” or “CompanyInc”, and put that affiliate code ( ?ref=Bob ) at the end of any of your store URL’s (i.e. http://www.yourstore.com?ref=Bob, http://www.yourstore.com/books/?ref=Bob, http://www.yourstore.com/books/harry-potter/?ref=Bob ).

To track any sales that came as a result of referrals go to your WP e-Commerce “Store Sales” page and check either the sale detail page or CSV export of your sales. The CSV export is the easiest way to see all referral sales at once. The referral code will be listed as “How User Found Us: JohnDoe”.

This method is especially simple and beneficial to small/medium online stores who don’t need all the features of a full-featured affiliate system, especially considering the complexity of integrating such an affiliate system with WP e-Commerce.

How to Implement

Simply follow these steps:

  1. From your WordPress Dashboard go to “Settings” –> “Store” and then the “Marketing” tab. Check the box to turn on the “Display How Customer Found Us Survey” (hopefully you weren’t planning on using that feature, because this is a slight modification that’s going to change what it does). Now click update.
  2. Download, install and activate the WordPress “Cookie Monster” plugin.
  3. From your WordPress Dashboard go to “Settings” –> “Cookie Monster”. In the box next to “URL Parameter 1 :” enter “ref” (ref without quotations). Click “Update options”.
  4. Open “wpsc-shopping_cart_page.php” in your theme files… (You may want to make a backup copy of this file before changing it, and also another backup copy after changing it, in case it ever gets over-written, or you want to remove the changes)

Find this code:

<?php if (wpsc_show_find_us()) : ?>
         <td><label for='how_find_us'><?php _e('How did you find us' , 'wpsc'); ?></label></td>
            <select name='how_find_us'>
               <option value='Word of Mouth'><?php _e('Word of mouth' , 'wpsc'); ?></option>
               <option value='Advertisement'><?php _e('Advertising' , 'wpsc'); ?></option>
               <option value='Internet'><?php _e('Internet' , 'wpsc'); ?></option>
               <option value='Customer'><?php _e('Existing Customer' , 'wpsc'); ?></option>
<?php endif; ?>

Replace with this code:

<?php if (wpsc_show_find_us()) : ?>
          <td colspan='2' style="height: 5px;">
              <input class="text" value="<?php echo $_COOKIE[get_option('cookie_param1')]; ?>" name="how_find_us" type="hidden">
<?php endif; ?>

It’s possible that your code is going to be a little bit different than mine, the important thing is to replace the “how_find_us” drop-down form code with a hidden input field that grabs the referral cookie code…

<input class="text" value="<?php echo $_COOKIE[get_option('cookie_param1')]; ?>" name="how_find_us" type="hidden">

That’s it! You’re done.

You may want to make a test purchase to verify that it’s working. (Be sure to visit your store with a ref code in the URL, i.e. http://www.yourstore.com?ref=Bob )

Contact / Get a Quote