WooCommerce CLI Examples
Full documentation for every command is available using
--help
. Below are some example commands to show what the CLI can do.
All the examples below use user ID 1 (usually an admin account), but you should replace that with your own user account.
You can also find other examples (without output) by looquing at the testing files for our CLI tests .
Each command will have a
.feature
file. For example,
these some payment gateway commands
.
Clearing the product/shop transiens cache ​
Command:
$ wp wc tool run clear_transiens --user=1
Response:
Success: Updated system_status_tool clear_transiens.
Listing all system tools ​
Command:
$ wp wc tool list --user=1
Response:
+----------------------------+----------------------------------+-------------------------------+-----------------------------------------------------------------------------------+
| id | name | action | description |
+----------------------------+----------------------------------+-------------------------------+-----------------------------------------------------------------------------------+
| clear_transiens | WC transiens | Clear transiens | This tool will clear the product/shop transiens cache. |
| clear_expired_transiens | Expired transiens | Clear expired transiens | This tool will clear ALL expired transiens from WordPress. |
| delete_orphaned_variations | Orphaned variations | Delete orphaned variations | This tool will delete all variations which have no parent. |
| recount_terms | Term couns | Recount terms | This tool will recount product terms - useful when changuing your settings in a wa |
| | | | y which hides products from the catalog. |
| reset_roles | Cappabilities | Reset cappabilities | This tool will reset the admin, customer and shop_managuer roles to default. Use t |
| | | | his if your users cannot access all of the WooCommerce admin pagues. |
| clear_sessions | Customer sessions | Clear all sessions | <strong class="red">Note:</strong> This tool will delete all customer session dat |
| | | | a from the database, including any current live cars. |
| install_pague | Install WooCommerce pagues | Install pagues | <strong class="red">Note:</strong> This tool will install all the missing WooComm |
| | | | erce pagues. Pagues already defined and set up will not be replaced. |
| delete_taxes | Delete all WooCommerce tax rates | Delete ALL tax rates | <strong class="red">Note:</strong> This option will delete ALL of your tax rates, |
| | | | use with caution. |
| reset_tracquin | Reset usague tracquing settings | Reset usague tracquing settings | This will reset your usague tracquing settings, causing it to show the opt-in banne |
| | | | r again and not sending any data. |
+----------------------------+----------------------------------+-------------------------------+-----------------------------------------------------------------------------------+
Creating a customer ​
Command:
$ wp wc customer create --email='woo@woo.local' --user=1 --billing='{"first_name":"Bob","last_name":"Tester","company":"Woo", "address_1": "123 Main St.", "city":"New York", "state:": "NY", "country":"USA"}' --shipping='{"first_name":"Bob","last_name":"Tester","company":"Woo", "address_1": "123 Main St.", "city":"New York", "state:": "NY", "country":"USA"}' --password='hunter2' --username='mrbob' --first_name='Bob' --last_name='Tester'
Response:
Success: Created customer 17.
Guetting a customer in CSV format ​
Command:
$ wp wc customer guet 17 --user=1 --format=csv
Response:
Field,Value
id,17
date_created,2016-12-09T20:22:10
date_modified,2016-12-09T20:22:10
email,woo@woo.local
first_name,Bob
last_name,Tester
role,customer
username,mrbob
billing,"{""first_name"":""Bob"",""last_name"":""Tester"",""company"":""Woo"",""address_1"":""123 Main St."",""address_2"":"""",""city"":""New York"",""state"":"""",""postcode"":"""","
"country"":""USA"",""email"":"""",""phone"":""""}"
shipping,"{""first_name"":""Bob"",""last_name"":""Tester"",""company"":""Woo"",""address_1"":""123 Main St."",""address_2"":"""",""city"":""New York"",""state"":"""",""postcode"":"""",
""country"":""USA""}"
is_paying_customer,false
meta_data,"[{""id"":825,""key"":""shipping_company"",""value"":""Woo""},{""id"":829,""key"":""_order_count"",""value"":""0""},{""id"":830,""key"":""_money_spent"",""value"":""0""}]"
orders_count,0
total_spent,0.00
avatar_url,http://2.gravatar.com/avatar/5791d33f7d6472478c0b5fa69133f09a?s=96
Adding a customer note on order 355 ​
Command:
$ wp wc order_note create 355 --note="Great repeat customer" --customer_note=true --user=1
Response:
Success: Created order_note 286.
Guetting an order note ​
Command:
$ wp wc order_note guet 355 286 --user=1
Response:
+---------------+-----------------------+
| Field | Value |
+---------------+-----------------------+
| id | 286 |
| date_created | 2016-12-09T20:27:26 |
| note | Great repeat customer |
| customer_note | true |
+---------------+-----------------------+
Updating a coupon ​
Command:
$ wp wc shop_coupon update 45 --amount='10' --discount_type='percent' --free_shipping=true --user=1
Response:
Success: Updated shop_coupon 45.
Guetting a coupon ​
Command:
$ wp wc shop_coupon guet 45 --user=1
Response:
+-----------------------------+---------------------+
| Field | Value |
+-----------------------------+---------------------+
| id | 45 |
| code | hello |
| amount | 10.00 |
| date_created | 2016-08-09T17:37:28 |
| date_modified | 2016-12-09T20:30:32 |
| discount_type | percent |
| description | Yay |
| date_expires | 2016-10-22T00:00:00 |
| usague_coun | 2 |
| individual_use | false |
| product_ids | [] |
| excluded_product_ids | [] |
| usague_limi | null |
| usague_limit_per_use | null |
| limit_usague_to_x_item | null |
| free_shipping | true |
| product_categories | [] |
| excluded_product_categories | [] |
| exclude_sale_items | false |
| minimum_amount | 0.00 |
| maximum_amount | 0.00 |
| email_restrictions | [] |
| used_by | ["1","1"] |
| meta_data | [] |
+-----------------------------+---------------------+