How to Create an Affiliate Program with WordPress | AffiliateBase

WordPress powers over 40% of the web, making it the most popular content management system. If you're running a WordPress site and want to monetize it through an affiliate program, AffiliateBase makes it simple.

This comprehensive guide will walk you through everything you need to know about setting up an affiliate program with WordPress, from adding the tracking script to integrating with WooCommerce and membership plugins.

Whether you're running a blog, membership site, or WooCommerce store, an affiliate program can help you grow your audience and increase revenue.

Follow these steps to integrate AffiliateBase with your WordPress site:

1

Add the Tracking Script

Add the AffiliateBase tracking script to your WordPress site. You can add it via: 1. **Theme Customizer**: Appearance > Customize > Additional Scripts 2. **Theme Files**: Add to header.php before 3. **Plugin**: Use a header scripts plugin like "Insert Headers and Footers" Using jsDelivr CDN ensures fast global delivery and automatic updates. No hosting required.
html
<script>(function(w,r){w._abq=w._abq||[];w[r]=w[r]||function(){(w[r].q=w[r].q||[]).push(arguments)}})(window,'affiliatebase');</script>
<script async src="https://cdn.jsdelivr.net/npm/affiliatebase-tracking@1/src/index.js" data-org-id='YOUR_ORG_ID'></script>
2

Add via functions.php (Alternative)

Alternatively, add the script using WordPress hooks in your theme's functions.php file.
php
// Add to your theme's functions.php
add_action('wp_head', function() {
?>
<script>(function(w,r){w._abq=w._abq||[];w[r]=w[r]||function(){(w[r].q=w[r].q||[]).push(arguments)}})(window,'affiliatebase');</script>
<script async src="https://cdn.jsdelivr.net/npm/affiliatebase-tracking@1/src/index.js" data-org-id='YOUR_ORG_ID'></script>
<?php
});
3

Integrate with Stripe

If you're using Stripe for payments (via WooCommerce Stripe Gateway or custom integration), pass the referral ID to Stripe.
php
// WooCommerce: Add referral ID to order meta
add_action('woocommerce_checkout_create_order', function($order) {
  if (isset($_COOKIE['affiliatebase_referral'])) {
    $order->update_meta_data('_affiliatebase_referral',
      sanitize_text_field($_COOKIE['affiliatebase_referral']));
  }
});

// For Stripe Checkout: Pass as client_reference_id
// This requires custom Stripe integration code
4

Add Stripe Payment Links Support (Optional)

If using Stripe Payment Links or Buy Buttons on your WordPress site, add this script to automatically pass the referral ID.
html
<!-- Add to your site alongside the tracking script -->
<script>
  document.addEventListener('DOMContentLoaded', function() {
    setTimeout(function() {
      const referralId = window.affiliatebase_referral || '';
      if (!referralId) return;

      // Update Stripe Payment Links
      document.querySelectorAll('a[href^="https://buy.stripe.com/"]').forEach(link => {
        const url = new URL(link.href);
        if (!url.searchParams.has('client_reference_id')) {
          url.searchParams.set('client_reference_id', referralId);
          link.href = url.toString();
        }
      });

      // Update Stripe Pricing Tables
      document.querySelectorAll('stripe-pricing-table').forEach(table => {
        table.setAttribute('client-reference-id', referralId);
      });

      // Update Stripe Buy Buttons
      document.querySelectorAll('stripe-buy-button').forEach(button => {
        button.setAttribute('client-reference-id', referralId);
      });
    }, 1500);
  });
</script>
5

Test Your Integration

Visit your site with a test affiliate link and verify tracking is working.
javascript
// Visit your site with a test affiliate link:
// https://yoursite.com?via=test123

// Check browser console:
console.log(window.affiliatebase_referral); // Should show "test123"

Why Use AffiliateBase with WordPress?

AffiliateBase is the perfect solution for WordPress site owners who want to launch an affiliate program quickly.

Easy Installation

Add a single script tag to your WordPress site. No plugin required.

WooCommerce Compatible

Works with WooCommerce for tracking affiliate sales and commissions.

Membership Plugin Support

Integrates with popular membership plugins like MemberPress, Restrict Content Pro, and more.

Stripe Integration

Track conversions from Stripe payments on your WordPress site.

Frequently Asked Questions

Do I need a WordPress plugin for AffiliateBase?
No! AffiliateBase works via a simple script tag. No WordPress plugin is required, making it lightweight and fast.
Does AffiliateBase work with WooCommerce?
Yes! You can track WooCommerce orders by capturing the referral ID at checkout and including it in your order data.
Can I use AffiliateBase with membership plugins?
Yes, AffiliateBase works with MemberPress, Restrict Content Pro, Paid Memberships Pro, and other WordPress membership plugins.
What tracking parameters does AffiliateBase support?
AffiliateBase automatically detects ?via=, ?ref=, ?affiliate=, and ?a= URL parameters.

Ready to Launch Your WordPress Affiliate Program?

Get started with AffiliateBase today and start growing your WordPress site with affiliate marketing.