WooCommerce Memberships – CLI Reference

Overview ↑ Back to top

You can manage WooCommerce Memberships plans and members via WP CLI if installed in your environment. The primary command used by the plugin is: wp wc memberships

This will allow you to use our sub-commands:

  • memberships – manage user memberships
  • plan – manage membership plans

You can also use wp help wc memberships for additional information and in-context help.

CLI support was added in Memberships version 1.7.0, so you must be using this version or newer for CLI support.

wp wc memberships plan ↑ Back to top

You can manage plans with wp wc memberships plan subcommands:

command function
create Create a new membership plan
delete Delete an existing membership plan
update Update one or more membership plans
get Get a membership plan
list List membership plans

wp wc memberships plan create ↑ Back to top

Allows you to create new membership plans.

field required? values
name yes string – plan name, e.g., "Silver Plan"
slug no string – plan slug, e.g., "silver-plan"
access no string – way access is granted, e.g., "signup" (free or signup, purchase, manual-only)
length no string – plan duration (if set-length plan), e.g., "2 months"
product no int – comma-separated list of IDs that grant access, e.g., 123,409,8392
start_date no string - start date for membership (fixed dates), e.g., "2017-01-01"
end_date no string - end date for membership (fixed dates), e.g., "2017-12-31"
status no string - plan post status, e.g., "draft"

Plan create examples

wp wc memberships plan create --name="Gold Membership"
Creates an admin-assign only, unlimited plan named "Gold Membership"
wp wc memberships plan create --name="Silver" --slug="silver-plan" --length="1 month" --product=123,456,6780
Create a "Silver" plan that lasts 1 month, and grants access via purchase of products 123, 456, or 6780
wp wc memberships plan create --name="Bronze Plan" --start_date="2017-10-01" --end_date="2018-08-25"
Create a "Bronze Plan" that is accessed via admin assign only, and runs from Oct 1, 2017 to August 25, 2018
wp wc memberships plan create --name="Free Plan" --access="free"
Create a "Free Plan" that grants access upon registration and is unlimited in length.

wp wc memberships plan delete ↑ Back to top

Deletes a membership plan using ID:
wp wc memberships plan delete 123

You can also delete all plans at once:
wp wc memberships plan delete $(wp wc memberships plan list --format=ids)

wp wc memberships plan update ↑ Back to top

Allows you to update membership plans using the plan ID:
wp wc memberships plan update 123

field values
name string - new plan name, e.g., "Silver Plan"
slug string - new plan slug, e.g., "silver-plan"
access string - new access method, e.g., "signup" (free or signup, purchase, manual-only)
length string - new plan duration (set-length plan), e.g., "2 months"
product int - comma-separated list of IDs that now grant access, e.g., 123,409,8392
start_date string - new start date for membership (fixed dates), e.g., "2017-01-01"
end_date string - new end date for membership (fixed dates), e.g., "2017-12-31"
status string - new plan post status, e.g., "publish"

Plan update examples

wp wc memberships plan update 987 --name="New Name"
Updates the plan name of membership plan 987
wp wc memberships plan update 8762 --start_date="2016-01-01" --end_date="2016-12-31"
Updates the start and end dates of plan 8762
wp wc memberships plan update 333 --access="signup"
Changes plan 333 to grant access at registration

wp wc memberships plan get ↑ Back to top

Get data associated with a membership plan by ID:
wp wc memberships plan get 123

field values
field string - the field to get values for, e.g., --field="members_count" (slug, id, name, type, length, members_count, etc)
fields string - comma-separated list of fields to get values for, e.g., --fields="slug,members_count"
format string - the desired format for requested date, e.g., --format="json" (table, json, csv)

Get plan examples

wp wc memberships plan get 246
Gets all fields for plan 246
wp wc memberships plan get 343 --fields="id,slug,type,length,members_count"
Gets a selection of fields for plan 343
wp wc memberships plan get 8761 --format="json"
Gets plan data for membership plan 8761 in JSON formation

wp wc memberships plan list ↑ Back to top

Lists data associated with membership plans:
wp wc memberships plan list

field values
field string - print the value of a single field for all plans, e.g., --field="members_count" (slug, id, name, type, length, product_ids, members_count, status, start_date, end_date)
fields string - comma-separated list of fields to print values for, e.g., --fields="slug,members_count"
format string - the desired format for requested date, e.g., --format="json" (table, csv, json, count, ids)

Plan list examples

wp wc memberships plan list
Outputs a table of default data for all plans
wp wc memberships plan list --format="csv"
Provides a CSV formatted result of all membership plans
wp wc memberships plan list --fields="slug,members_count"
Outputs a list of plans with only the slug and member count.

wp wc memberships membership ↑ Back to top

You can manage user memberships with wp wc memberships membership subcommands:

command function
create Create a new user membership
delete Delete an existing user membership
update Update one or more user memberships
get Get a user membership
list List user memberships

wp wc memberships membership create ↑ Back to top

Allows you to create new user membership.

field required? values
customer yes int - the user ID for the member, e.g., --customer=22
plan yes int|string - plan ID or slug, e.g., --plan="silver-plan"
order no int - ID of order that granted access, e.g., --order=123
product no int - ID of product that granted access, e.g., --product=46
subscription no int - ID of subscription the membership is tied to, e.g., --subscription=125
status no string - membership status, e.g., --status="paused"
start_date no string - start date for the user membership, e.g., "2017-01-01"
end_date no string - end date for the user membership, e.g., "2017-12-31"

Membership creation examples

wp wc memberships membership create --customer=83 --plan=238
Creates an unlimited membership for user 83 to plan 238
wp wc memberships membership create --customer=101 --plan="silver" --start_date="2016-01-01" --end_date="2016-06-30" --status="expired"
Creates an expired silver membership for user 101 that started on Jan 1, 2016, and ended on June 30, 2016

wp wc memberships membership delete ↑ Back to top

Deletes a user membership using ID:
wp wc memberships membership delete 101

You can also delete all members at once:
wp wc memberships membership delete $(wp wc memberships membership list --format=ids)

wp wc memberships membership update ↑ Back to top

Allows you to update user memberships using the user membership ID:
wp wc memberships membership update 9809

field values
customer int - transfer the membership to a new user, --customer=296
plan int|string - new plan plan ID or slug, e.g., --plan="gold-plan"
order int - updated ID of order that granted access, e.g., --order=236
product int - updated ID of product that granted access, e.g., --product=502
subscription int - updated ID of subscription the membership is tied to, e.g., --subscription=9862
status string - updated membership status, e.g., --status="cancelled"
start_date string - updated start date for the user membership, e.g., "2017-07-01"
end_date string - updated end date for the user membership, e.g., "2018-07-01"

Membership update examples

wp wc memberships membership update 232 --customer=876
Transfers user membership 232 to user 876
wp wc memberships membership update 8762 --end_date="2017-01-01" --status="active"
Updates the end date and status of user membership 8762
wp wc memberships membership update 776 --plan=126
Changes user membership 776 to use plan 126

wp wc memberships membership get ↑ Back to top

Get data associated with a user membership by ID:
wp wc memberships membership get 653

field values
field string - the field to get values for, e.g., --field="status" (id, user_id, plan_id, plan, status, start_date, end_date)
fields string - comma-separated list of fields to get values for, e.g., --fields="plan,status"
format string - the desired format for requested date, e.g., --format="json" (table, json, csv)

Get membership examples

wp wc memberships membership get 848
Gets all fields for user membership 848
wp wc memberships membership get 848 --fields="plan,status"
Gets the plan and status for user membership 848
wp wc memberships membership get 848 --format="json"
Gets data for user membership 848 in JSON formation

wp wc memberships membership list ↑ Back to top

Lists data associated with all user memberships:
wp wc memberships membership list

field values
field string - print the value of a single field for all memberships, e.g., --field="user_id" (id, user_id, plan_id, plan, status, start_date, end_date, subscription)
fields string - comma-separated list of fields to print values for, e.g., --fields="plan,status"
format string - the desired format for requested date, e.g., --format="json" (table, csv, json, count, ids)

Plan list examples

wp wc memberships memberships list
Outputs a table of default data for all memberships
wp wc memberships memberships list --format="csv"
Provides a CSV formatted result of all user memberships
wp wc memberships memberships list --fields="plan_id, status"
Outputs a list of memberships with only the plan ID and membership status.

CLI Extensions ↑ Back to top

Here's a helpful community plugin to replicate the CSV Import functionality of Memberships via the command line. This is a nifty tool for developers to allow them to import memberships via the command line without timeouts, helpful for large data sets.

Questions & Support

Looking for questions or support? You can submit a request right from your account.

WooCommerce - the most customizable eCommerce platform for building your online business.

Back to the top