WP-CLI - Payout Commands

AffiliateWP 1.9+ brings affiliate management to the command-line with the introduction of the wp affwp affiliate WP-CLI command.

Usage: wp affwp affiliate <sub-command>

There are five affiliate sub-commands to choose from:

  • create – Creates an affiliate account.
  • delete – Deletes an affiliate.
  • get – Retrieves an affiliate object or field(s) by ID.
  • list – Displays a list of affiliates.
  • update – Updates an existing affiliate.

Clicking any of the sub-command listed above will take you to more comprehensive documentation about the arguments they require and options available.

Be careful!

Sub-commands like delete or update have the very real possibility of wreaking havoc on your AffiliateWP data when not used with caution. Make sure you know what you're changing or removing, and heed confirmation messages when executing sub-commands.


create

The affwp affiliate create sub-command is used to create new affiliate accounts.

Usage: wp affwp affiliate create <username|user_id> [--payment_email=<email>] [--rate=<float>] [--rate_type=<type>] [--status=<status>] [--earnings=<number>] [--referrals=<number>] [--visits=<number>]

Note: create assumes you already added a user account and have a user ID or username to pass as the first argument, which is required.

Options

All options are optional unless noted otherwise.

  • username|user_id (required)
    Username or ID for an existing user.
  • --payment_email
    Affiliate payment email. If not specified, the user account email will be used.
  • --rate
    Referral rate. If not specified, the default rate will be used.
  • --rate_type
    Referral rate type. Accepts 'percentage', 'flat', or any custom rate type. If not specified, the default rate type will be used.
  • --status
    Affiliate status. Accepts 'active', 'inactive', or 'pending'. If not specified, and new affiliates require approval per global settings, 'pending' will used. Otherwise, the default status of 'active' will be used.
  • --earnings
    Affiliate earnings. If not specified, 0 will be used.
  • --referrals
    Number of referrals. If not specified, 0 will be used.
  • --visits
    Number of visits. If not specified, 0 will be used.

Examples

# Creates an affiliate with a 20% referral rate.
wp affwp affiliate create edduser1 --rate=0.2 --rate_type=percentage


# Creates an affiliate with the default referral rate, rate type,
#specified payment email, and 20 visits.
wp affwp affiliate create woouser1 --payment_email=affwprocks@woo.dev --visits=20


# Creates an affiliate for user ID 142 with a status of 'pending'.
wp affwp affiliate create 142 --status=pending

delete

The affwp affiliate delete sub-command is used to delete affiliate accounts.

Usage: wp affwp affiliate delete <username|affiliate_id> [--delete_data] [--delete_user] [--network]

Options

All options are optional unless noted otherwise.

  • <username|affiliate_id> (required)
    Username or affiliate ID.
  • --delete_data
    Whether to delete affiliate data, such as referrals, visits, etc. Data will be retained by default.
  • --delete_user
    Whether to delete the user account associated with the affiliate account. Default false.
  • --network
    Whether to delete the user account network-wide (multisite only). Ignored if --delete_user is omitted. Use with caution. Default false.

Examples

# Deletes the affiliateuser03 account, retaining its associated data and user account
wp affwp affiliate delete affiliateuser03

# Deletes the affiliate with ID 636 along with its associated data
wp affwp affiliate delete 636 --delete_data

# Deletes the networkuser25 affiliate and its associated user account
wp affwp affiliate delete networkuser25 --delete_user

get

The affwp affiliate get sub-command is used to retrieve a single affiliate object.

Usage: wp affwp affiliate get <affiliate_id> [--field=<field>] [--fields=<fields>] [--format=<format>]

Options

All options are optional unless noted otherwise.

  • <affiliate_id> (required)
    The affiliate ID to retrieve.
  • --field
    Instead of returning the whole affiliate object, returns the value of a single field.
  • --fields
    Limit the output to specific fields. Defaults to all fields.
  • --format
    Accepted values: table, json, csv, yaml. Default: table

Examples

# save the affiliate field value to a file
wp post get 12 --field=earnings > earnings.txt

list

The affwp affiliate list sub-command is used to list out affiliates based on given criteria.

Usage: wp affwp affiliate list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]

Options

All options are optional unless noted otherwise.

--
One or more args to pass to get_affiliates(). 'user_login' and 'name' are not affiliate fields and will be ignored.

  • --field
    Prints the value of a single field for each affiliate.
  • --fields
    Limit the output to specific affiliate fields.
  • --format
    Accepted values: table, csv, json, count, ids, yaml. Default: table
Available Fields

These fields will be displayed by default for each affiliate:

  • ID (alias for affiliate_id)
  • name
  • user_login
  • user_id
  • rate
  • rate_type
  • status
  • earnings
  • referrals
  • visits
  • date_registered

Examples

# Lists affiliates by affiliate_id
wp affwp affiliate list --field=affiliate_id

# Outputs a table with affiliate_id, rate, and earnings columns for affiliates set
# as the 'percentage' rate type
wp affwp affiliate list --rate_type=percentage --fields=affiliate_id,rate,earnings

# Outputs a table with standard user_login, affiliate_id, earnings, referrals, and
# visits columns, ordered by status ascending.
affwp affiliate list --orderby=status --order=ASC

update

The affwp affiliate update sub-command is used to update a single affiliate based on given criteria.

Usage: wp affwp affiliate update <username|id> [--account_email=<email>] [--payment_email=<email>] [--rate=<float>] [--rate_type=<type>] [--status=<status>]

Options

All options are optional unless noted otherwise.