Export referral codes

Use this to get a spreadsheet of customers and their referral codes, for example to import into an email platform. If you use Klaviyo, Mailchimp, Brevo or Omnisend, the built-in integrations can send codes for you. See Integrations overview.

1. Create missing codes

Customers get a code when they register or first see their referral link. To give everyone a code first, run Create referrals in WooCommerce → Status → Tools. See Generate referral codes for existing customers.

2. Export registered customers

  1. Install Import and export users and customers, from the WordPress plugin directory.
  2. Go to Tools → Import and export users and customers → Export.
  3. In Columns, enter user_email,first_name,gens_referral_id.
  4. Click Download.

The gens_referral_id column holds each customer’s code. Each referral link is your landing page URL followed by ?raf= and the code, for example https://yourstore.com/?raf=ref1938475.

Export with WP-CLI

If you have WP-CLI, this exports the same data. Replace wp_ if your database uses a different table prefix.

wp db query "SELECT u.user_email, m.meta_value AS referral_code FROM wp_users u JOIN wp_usermeta m ON m.user_id = u.ID AND m.meta_key = 'gens_referral_id'" > referral-codes.tsv

Guest advocates

Codes created by guests aren’t attached to user accounts, so the exports above don’t include them. They’re stored in the wp_gens_raf_guest_referrals database table, with the email, name and code. Export it with your database tool, or with WP-CLI:

wp db query "SELECT email, name, referral_code FROM wp_gens_raf_guest_referrals" > guest-referral-codes.tsv

The exported file contains customers’ email addresses. Store it securely and delete it when you’re done.

Related

Browse our plugins

Lightweight WooCommerce plugins built for speed. No bloat, no frameworks -- just clean code that works.

View all plugins
Stay in the loop

Get notified when we launch new plugins. No spam, just product updates.