WooCommerce Memberships – CLI Reference

Overview

Starting from Memberships 1.13.0, the CLI implementation has switched to WC REST API. While the legacy WP CLI commands will still work, they are currently deprecated and will be removed at a later date.

You can manage WooCommerce Memberships plans and members via WP CLI if installed in your environment. There are two additional subcommands added to the WC CLI implementation: user_membership and membership_plan.

For further details please see the CLI help topics: wp help wc user_membership and wp help wc membership_plan.

All versions can still use our legacy WP CLI implementation too. This will allow you to use the primary command of wp wc memberships followed by our sub-commands:

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

If you are looking to create and edit membership plans, then you will need to use the legacy CLI for the time being. You can also use wp help wc memberships for additional information and in-context help.

 

wp wc membership_plan

You can read plans with the wp wc membership_plan subcommands:

COMMAND FUNCTION
get Get a membership plan
list List membership plans

 

wp wc membership_plan get

Get data associated with a membership plan by ID:
wp wc membership_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 membership_plan get 246
Gets all fields for plan 246
wp wc membership_plan get 343 --fields="id,slug,type,length,members_count"
Gets a selection of fields for plan 343
wp wc membership_plan get 8761 --format="json"
Gets plan data for membership plan 8761 in JSON formation

 

wp wc membership_plan list

Lists data associated with membership plans:
wp wc membership_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 membership_plan list
Outputs a table of default data for all plans
wp wc membership_plan list --format="csv"
Provides a CSV formatted result of all membership plans
wp wc membership_plan list --fields="slug,members_count"
Outputs a list of plans with only the slug and member count.

 

wp wc user_membership

You can manage user memberships with wp wc user_membership subcommands:

COMMAND FUNCTION
create Create a new user membership
delete Delete an existing user membership
get Get a user membership
list List user memberships
import Import user memberships
update Update one or more user memberships

 

wp wc user_membership create

Allows you to create new user membership.

FIELD REQUIRED? VALUES
customer_id yes int – the user ID for the member, e.g., --customer_id=22
plan_id yes int|string – plan ID or slug, e.g., --plan_id="silver-plan"
status no string – membership status, e.g., --status="paused"
order_id no int – ID of order that granted access, e.g., --order_id=123
product_id no int – ID of product that granted access, e.g., --product_id=46
start_date_gmt no string – start date for the user membership in UTC, e.g., "2017-01-01"
end_date_gmt no string – end date for the user membership in UTC, e.g., "2017-12-31"
cancelled_date_gmt no string – cancellation date for the user membership in UTC, e.g., "2017-01-01"
paused_date_gmt no string – last paused date for the user membership in UTC, e.g., "2017-12-31"
meta_data no array – any WordPress post meta data to be set on the membership. Each array item has an “id” (integer), a “key” (string) and a “value” (either a boolean, an integer, or string, which could also represent serialized data).
subscription_id no int – ID of subscription the membership is tied to, e.g., --subscription_id=125
subscription no int – ID of subscription the membership is tied to, e.g., --subscription=125
installment_plan no string – if the user membership should be part of an installment plan (“Y” or “N”) e.g., --installment_plan="Y"

 

User Membership creation examples

wp wc user_membership create --customer_id=83 --plan_id=238
Creates an unlimited membership for user 83 to plan 238
wp wc user_membership create --customer_id=101 --plan_id="silver" --start_date_gmt="2016-01-01" --end_date_gmt="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 user_membership delete

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

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

 

wp wc user_membership update

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

FIELD VALUES
plan_id int|string – new plan plan ID or slug, e.g., --plan_id="gold-plan"
status string – updated membership status, e.g., --status="cancelled"
start_date_gmt string – updated start date for the user membership, e.g., "2017-07-01"
end_date_gmt string – updated end date for the user membership, e.g., "2018-07-01"
paused_date_gmt string – last paused date for the user membership in UTC, e.g., "2017-12-31"
cancelled_date_gmt string – cancellation date for the user membership in UTC, e.g., "2017-01-01"
meta_data array – any WordPress post meta data to be set on the membership. Each array item has an “id” (integer), a “key” (string) and a “value” (either a boolean, an integer, or string, which could also represent serialized data).
subscription_id int – ID of subscription the membership is tied to, e.g., --subscription_id=125
subscription int – ID of subscription the membership is tied to, e.g., --subscription=125
installment_plan string – if the user membership should be part of an installment plan (“Y” or “N”) e.g., --installment_plan="Y"

 

User Membership update examples

wp wc user_membership update 8762 --end_date_gmt="2017-01-01" --status="active"
Updates the end date and status of user membership 8762
wp wc user_membership update 776 --plan_id=126
Changes user membership 776 to use plan 126

 

wp wc user_membership get

Get data associated with a user membership by ID:
wp wc user_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 user membership examples

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

 

wp wc user_membership list

Lists data associated with all user memberships:
wp wc user_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)

 

User Membership list examples

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

 

wp wc user_membership import

Import a csv file of user_memberships to be created or merged:
wp wc user_membership import user_memberships.csv

FIELD VALUES
fields_delimiter string – the field delimiter used in the CSV file, e.g., --fields_delimiter="|"
timezone string – the timezone in which all dates from imported CSV data are assumed to be (defaults to the current site timezone)
default_start_date string – default start date of imported user memberships when a date is not specified from CSV data (defaults to today’s date), e.g., "2018-07-01"
create_new_memberships string – if new memberships should be created if not found from CSV data, (“yes” or “no”) e.g., --create_new_memberships="yes"
merge_existing_memberships string – if memberships should be merged when matching data is found from the CSV file, (“yes” or “no”) e.g., --merge_existing_memberships="yes"
allow_memberships_transfer string – allow transferring user memberships between users if a different owner is specified in CSV data, (“yes” or “no”) e.g., --allow_memberships_transfer="yes"
create_new_users string – if users should be created from CSV data when no existing user could be found, (“yes” or “no”) e.g., --create_new_users="no"
notify_new_users string – whether to send email notifications when a new user is created during an import process, (“yes” or “no”) e.g., --notify_new_users="no"

 

Legacy CLI

Versions prior to 1.13.0 can still use our legacy WP CLI implementation. We would recommend updating any command line tooling to the updated WC REST API implementation where possible, as the following commands are now considered deprecated and will be removed at a later date.

 

wp wc memberships plan

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

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

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

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

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

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

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

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

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

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

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

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)

 

User membership 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

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

Was this article helpful?
Dislike 0
Views: 30