WooCommerce 文档

title: "WooCommerce CLI 示例" post_status: publish comment_status: open taxonomy: category: - woocommerce post_tag: - Wc Cli - Repos - Data


WooCommerce CLI 示例

每个 Command 的完整 Documentation 可以使用 --help 参数查看。 以下是一些示例 Command,以展示 CLI 的功能。

以下所有示例都使用用户 ID 1(通常是 Admin 账户),但您应该将其替换为您的用户账户。

您还可以通过查看 我们 CLI 测试的测试文件 找到其他示例(不包含 Output)。

每个 Command 都有一个 .feature 文件。 例如,这些是关于 Payment Gateway 的一些 Command

清除 Product / 商店的 Transient 缓存

Command:

$ wp wc tool run clear_transients --user=1

Response:

Success: Updated system_status_tool clear_transients.

列表显示所有系统工具

命令:

$ wp wc tool list --user=1

回复:

WooCommerce 工具箱

本工具箱提供了多种实用功能,用于管理和维护您的 WooCommerce 商店。

工具列表

以下是可用的工具列表:

+----------------------------+----------------------------------+-------------------------------+-----------------------------------------------------------------------------------+
| id                         | name                             | action                        | description                                                                       |
+----------------------------+----------------------------------+-------------------------------+-----------------------------------------------------------------------------------+
| clear_transients           | WC 瞬态对象                    | 清理瞬态对象              | 此工具将清理产品/商店的瞬态对象缓存。                           |
| clear_expired_transients   | 过期瞬态对象               | 清理过期瞬态对象      | 此工具将清理 WordPress 中的所有过期瞬态对象。                       |
| delete_orphaned_variations | 孤立的变体              | 删除孤立的变体    | 此工具将删除所有没有父对象的变体。                        |
| recount_terms              | 产品分类计数                      | 重新计算产品分类计数                 | 此工具将重新计算产品分类计数,当您以隐藏产品于目录的方式更改设置时非常有用。 |
|                            |                                  |                               |                                                                       |
| reset_roles                | 权限                     | 重置权限            | 此工具会将管理员、客户和商店管理员角色重置为默认值。 如果您的用户无法访问所有 WooCommerce 管理页面,请使用此功能。               |
|                            |                                  |                               |                                                                       |
| clear_sessions             | 客户会话                | 清理所有会话            | <strong class="red">注意:</strong> 此工具将删除所有客户会话数据,包括任何当前的购物车内容。                            |
|                            |                                  |                               |                                                                       |
| install_pages              | 安装 WooCommerce 页面        | 安装页面                 | <strong class="red">注意:</strong> 此工具将安装所有缺失的 WooCommerce 页面。 已经定义和设置的页面不会被替换。                |
|                            |                                  |                               |                                                                       |
| delete_taxes               | 删除所有 WooCommerce 税率 | 删除所有税率          | <strong class="red">注意:</strong> 此选项将删除所有税率,请谨慎使用。                                                                |
|                            |                                  |                               |                                                                       |
| reset_tracking             | 重置使用情况跟踪设置    | 重置使用情况跟踪设置 | 这将重置您的使用情况跟踪设置,导致它再次显示“选择加入”横幅,并且不会发送任何数据。                                                 |
|                            |                                  |                               |                                                                       |
+----------------------------+----------------------------------+-------------------------------+-----------------------------------------------------------------------------------+

工具说明:

使用方法:

  1. 选择您要使用的工具。
  2. 点击相应的按钮或链接。
  3. 根据提示完成操作。

注意事项:

常见问题:

更多信息:

术语表:

创建客户

命令:

$ 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'

响应:

Success: Created customer 17.

以 CSV 格式获取客户

命令:

$ wp wc customer get 17 --user=1 --format=csv

响应:

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,客户
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

在订单 355 上添加客户备注

命令:

$ wp wc order_note create 355 --note="Great repeat customer" --customer_note=true --user=1

响应:

Success: Created order_note 286.

获取订单备注

命令:

$ wp wc order_note get 355 286 --user=1

响应:

+---------------+-----------------------+
| Field         | Value                 |
+---------------+-----------------------+
| id            | 286                   |
| date_created  | 2016-12-09T20:27:26   |
| note          | Great repeat customer |
| customer_note | true                  |
+---------------+-----------------------+

更新优惠券

命令:

$ wp wc shop_coupon update 45 --amount='10' --discount_type='percent' --free_shipping=true --user=1

响应:

Success: Updated shop_coupon 45.

获取优惠券

命令:

$ wp wc shop_coupon get 45 --user=1

响应:

+-----------------------------+---------------------+
| 字段                       |                    |

+-----------------------------+---------------------+
| 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 |
| usage_count                 | 2                   |
| individual_use              | false               |
| product_ids                 | []                  |
| excluded_product_ids        | []                  |
| usage_limit                 | null                |
| usage_limit_per_user        | null                |
| limit_usage_to_x_items      | 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                   | []                  |
+-----------------------------+---------------------+

使用 WP CLI 升级数据库

当 WooCommerce 发布新版本时,通常会提示您运行数据库升级。 虽然可以通过 WP 后台进行此操作,但高级用户可能更喜欢通过 CLI 运行这些升级,例如在繁忙的商店中,以避免可能发生的超时。

要更新数据库,请使用以下 CLI 命令:

$ wp wc update

不需要额外的参数,只会运行待审的升级。 升级完成后,将显示新的版本。