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:

COMMANDFUNCTION
getGet a membership plan
listList membership plans

 

wp wc membership_plan get

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

FIELDVALUES
fieldstring – the field to get values for, e.g., --field="members_count" (slug, id, name, type, length, members_count, etc)
fieldsstring – comma-separated list of fields to get values for, e.g., --fields="slug,members_count"
formatstring – 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

FIELDVALUES
fieldstring – 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)
fieldsstring – comma-separated list of fields to print values for, e.g., --fields="slug,members_count"
formatstring – 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:

COMMANDFUNCTION
createCreate a new user membership
deleteDelete an existing user membership
getGet a user membership
listList user memberships
importImport user memberships
updateUpdate one or more user memberships

 

wp wc user_membership create

Allows you to create new user membership.

FIELDREQUIRED?VALUES
customer_idyesint – the user ID for the member, e.g., --customer_id=22
plan_idyesint|string – plan ID or slug, e.g., --plan_id="silver-plan"
statusnostring – membership status, e.g., --status="paused"
order_idnoint – ID of order that granted access, e.g., --order_id=123
product_idnoint – ID of product that granted access, e.g., --product_id=46
start_date_gmtnostring – start date for the user membership in UTC, e.g., "2017-01-01"
end_date_gmtnostring – end date for the user membership in UTC, e.g., "2017-12-31"
cancelled_date_gmtnostring – cancellation date for the user membership in UTC, e.g., "2017-01-01"
paused_date_gmtnostring – last paused date for the user membership in UTC, e.g., "2017-12-31"
meta_datanoarray – 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_idnoint – ID of subscription the membership is tied to, e.g., --subscription_id=125
subscriptionnoint – ID of subscription the membership is tied to, e.g., --subscription=125
installment_plannostring – 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

FIELDVALUES
plan_idint|string – new plan plan ID or slug, e.g., --plan_id="gold-plan"
statusstring – updated membership status, e.g., --status="cancelled"
start_date_gmtstring – updated start date for the user membership, e.g., "2017-07-01"
end_date_gmtstring – updated end date for the user membership, e.g., "2018-07-01"
paused_date_gmtstring – last paused date for the user membership in UTC, e.g., "2017-12-31"
cancelled_date_gmtstring – cancellation date for the user membership in UTC, e.g., "2017-01-01"
meta_dataarray – 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_idint – ID of subscription the membership is tied to, e.g., --subscription_id=125
subscriptionint – ID of subscription the membership is tied to, e.g., --subscription=125
installment_planstring – 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

FIELDVALUES
fieldstring – the field to get values for, e.g., --field="status" (id, user_id, plan_id, plan, status, start_date, end_date)
fieldsstring – comma-separated list of fields to get values for, e.g., --fields="plan,status"
formatstring – 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

FIELDVALUES
fieldstring – 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)
fieldsstring – comma-separated list of fields to print values for, e.g., --fields="plan,status"
formatstring – 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

FIELDVALUES
fields_delimiterstring – the field delimiter used in the CSV file, e.g., --fields_delimiter="|"
timezonestring – the timezone in which all dates from imported CSV data are assumed to be (defaults to the current site timezone)
default_start_datestring – 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_membershipsstring – if new memberships should be created if not found from CSV data, (“yes” or “no”) e.g., --create_new_memberships="yes"
merge_existing_membershipsstring – 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_transferstring – 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_usersstring – 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_usersstring – 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:

COMMANDFUNCTION
createCreate a new membership plan
deleteDelete an existing membership plan
updateUpdate one or more membership plans
getGet a membership plan
listList membership plans

 

wp wc memberships plan create

Allows you to create new membership plans.

FIELDREQUIRED?VALUES
nameyesstring – plan name, e.g., "Silver Plan"
slugnostring – plan slug, e.g., "silver-plan"
accessnostring – way access is granted, e.g., "signup" (free or signup, purchase, manual-only)
lengthnostring – plan duration (if set-length plan), e.g., "2 months"
productnoint – comma-separated list of IDs that grant access, e.g., 123,409,8392
start_datenostring – start date for membership (fixed dates), e.g., "2017-01-01"
end_datenostring – end date for membership (fixed dates), e.g., "2017-12-31"
statusnostring – 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

FIELDVALUES
namestring – new plan name, e.g., "Silver Plan"
slugstring – new plan slug, e.g., "silver-plan"
accessstring – new access method, e.g., "signup" (free or signup, purchase, manual-only)
lengthstring – new plan duration (set-length plan), e.g., "2 months"
productint – comma-separated list of IDs that now grant access, e.g., 123,409,8392
start_datestring – new start date for membership (fixed dates), e.g., "2017-01-01"
end_datestring – new end date for membership (fixed dates), e.g., "2017-12-31"
statusstring – 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

FIELDVALUES
fieldstring – the field to get values for, e.g., --field="members_count" (slug, id, name, type, length, members_count, etc)
fieldsstring – comma-separated list of fields to get values for, e.g., --fields="slug,members_count"
formatstring – 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

FIELDVALUES
fieldstring – 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)
fieldsstring – comma-separated list of fields to print values for, e.g., --fields="slug,members_count"
formatstring – 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:

COMMANDFUNCTION
createCreate a new user membership
deleteDelete an existing user membership
updateUpdate one or more user memberships
getGet a user membership
listList user memberships

 

wp wc memberships membership create

Allows you to create new user membership.

FIELDREQUIRED?VALUES
customeryesint – the user ID for the member, e.g., --customer=22
planyesint|string – plan ID or slug, e.g., --plan="silver-plan"
ordernoint – ID of order that granted access, e.g., --order=123
productnoint – ID of product that granted access, e.g., --product=46
subscriptionnoint – ID of subscription the membership is tied to, e.g., --subscription=125
statusnostring – membership status, e.g., --status="paused"
start_datenostring – start date for the user membership, e.g., "2017-01-01"
end_datenostring – 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

FIELDVALUES
customerint – transfer the membership to a new user, --customer=296
planint|string – new plan plan ID or slug, e.g., --plan="gold-plan"
orderint – updated ID of order that granted access, e.g., --order=236
productint – updated ID of product that granted access, e.g., --product=502
subscriptionint – updated ID of subscription the membership is tied to, e.g., --subscription=9862
statusstring – updated membership status, e.g., --status="cancelled"
start_datestring – updated start date for the user membership, e.g., "2017-07-01"
end_datestring – 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

FIELDVALUES
fieldstring – the field to get values for, e.g., --field="status" (id, user_id, plan_id, plan, status, start_date, end_date)
fieldsstring – comma-separated list of fields to get values for, e.g., --fields="plan,status"
formatstring – 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

FIELDVALUES
fieldstring – 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)
fieldsstring – comma-separated list of fields to print values for, e.g., --fields="plan,status"
formatstring – 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: 1

Cart

Log in

Create an Account
Back to Top