255 lines
No EOL
12 KiB
Markdown
255 lines
No EOL
12 KiB
Markdown
---
|
||
post_title: WooCommerce CLI examples
|
||
sidebar_label: Examples
|
||
sidebar_position: 3
|
||
|
||
---
|
||
|
||
# WooCommerce CLI 示例
|
||
|
||
每个命令的完整文档可通过 `--help` 获取。以下是一些示例命令,展示 CLI 的功能。
|
||
|
||
以下所有示例都使用用户 ID 1(通常是管理员账户),但您应将其替换为您自己的用户账户。
|
||
|
||
您还可以通过查看 [CLI 测试的测试文件](https://github.com/woocommerce/woocommerce/tree/trunk/plugins/woocommerce/tests/cli/features) 来查找其他示例(无输出)。
|
||
|
||
每个命令都有一个 `.feature` 文件。例如,[这些是一些支付网关命令](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/tests/cli/features/payment_gateway.feature)。
|
||
|
||
## 清除产品/购物瞬态缓存
|
||
|
||
命令:
|
||
|
||
`$ wp wc tool run clear_transients --user=1`
|
||
|
||
响应:
|
||
|
||
`成功:已更新系统状态工具 clear_transients。`
|
||
|
||
## 列出所有系统工具
|
||
|
||
命令:
|
||
|
||
`$ wp wc tool list --user=1`
|
||
|
||
响应:
|
||
|
||
# WooCommerce 工具箱
|
||
|
||
本工具箱提供了多种实用功能,用于管理和维护您的 WooCommerce 商店。
|
||
|
||
## 工具列表
|
||
|
||
以下是可用的工具列表:
|
||
|
||
```bash
|
||
+----------------------------+----------------------------------+-------------------------------+-----------------------------------------------------------------------------------+
|
||
| 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 | 重置使用情况跟踪设置 | 重置使用情况跟踪设置 | 这将重置您的使用情况跟踪设置,导致它再次显示“选择加入”横幅,并且不会发送任何数据。 |
|
||
| | | | |
|
||
+----------------------------+----------------------------------+-------------------------------+-----------------------------------------------------------------------------------+
|
||
```
|
||
|
||
### 工具说明:
|
||
|
||
* **`clear_transients`**: 清理 WooCommerce 瞬态对象缓存。
|
||
* **`clear_expired_transients`**: 清理 WordPress 中所有过期的瞬态对象。
|
||
* **`delete_orphaned_variations`**: 删除没有父对象的变体。
|
||
* **`recount_terms`**: 重新计算产品分类计数。
|
||
* **`reset_roles`**: 重置管理员、客户和商店管理员角色的权限。
|
||
* **`clear_sessions`**: 清理所有客户会话数据。
|
||
* **`install_pages`**: 安装所有缺失的 WooCommerce 页面。
|
||
* **`delete_taxes`**: 删除所有 WooCommerce 税率。
|
||
* **`reset_tracking`**: 重置使用情况跟踪设置。
|
||
|
||
### 使用方法:
|
||
|
||
1. 选择您要使用的工具。
|
||
2. 点击相应的按钮或链接。
|
||
3. 根据提示完成操作。
|
||
|
||
### 注意事项:
|
||
|
||
* 某些工具可能会删除重要数据,请在使用前仔细阅读说明。
|
||
* 在进行任何更改之前,建议备份您的数据库。
|
||
|
||
### 常见问题:
|
||
|
||
* **如何安装 WooCommerce?** 请参考 [Install WooCommerce](https://example.com/install-woocommerce) 文档。
|
||
* **如何管理我的产品?** 请访问 WooCommerce 管理页面。
|
||
* **如何设置税率?** 请在 WooCommerce 设置中配置税率。
|
||
* **如何启用使用情况跟踪?** 请在 WooCommerce 设置中启用使用情况跟踪。
|
||
* **如何访问我的 WooCommerce 数据库?** 您可以使用数据库管理工具访问您的数据库。
|
||
* **如何修改 WooCommerce 的设置?** 您可以在 WooCommerce 设置页面修改各种选项。
|
||
* **如何删除 WooCommerce 页面?** 您可以使用 WordPress 的页面管理功能删除页面。
|
||
* **如何解决 WooCommerce 访问权限问题?** 请检查用户的角色和权限设置。
|
||
* **如何清除 WooCommerce 缓存?** 您可以使用缓存插件或手动清除缓存。
|
||
* **如何恢复 WooCommerce 数据库?** 您可以使用备份文件恢复数据库。
|
||
|
||
### 更多信息:
|
||
|
||
* [WooCommerce 官方网站](https://woocommerce.com/)
|
||
* [WooCommerce 文档](https://woocommerce.com/document/)
|
||
|
||
### 术语表:
|
||
|
||
* **瞬态 (Transient)**: 临时数据。
|
||
* **数据库 (Database)**: 存储数据的系统。
|
||
* **设置 (Settings)**: 配置选项。
|
||
* **安装 (Install)**: 将软件或插件添加到系统中。
|
||
* **角色 (Role)**: 用户权限级别。
|
||
* **网页 (Page)**: 网站页面。
|
||
* **安装 WooCommerce (Install WooCommerce)**: 将 WooCommerce 插件安装到 WordPress 网站。
|
||
* **使用情况跟踪 (Usage Tracking)**: 收集用户行为数据。
|
||
* **所有页面 (All Pages)**: 网站的所有页面。
|
||
* **税率 (Tax Rate)**: 增值税或其他税费的百分比。
|
||
* **跟踪 (Tracking)**: 监控和记录数据。
|
||
* **会话 (Session)**: 用户与网站的交互过程。
|
||
* **替换 (Replace)**: 用新的内容代替旧的内容。
|
||
* **当前 (Current)**: 当前状态或值。
|
||
* **产品 (Product)**: 商店中销售的商品或服务。
|
||
* **删除 (Delete)**: 移除或清除。
|
||
* **管理 (Manage)**: 组织和控制。
|
||
* **选项 (Option)**: 可选的配置或设置。
|
||
* **访问 (Access)**: 访问权限。
|
||
* **缓存 (Cache)**: 临时存储数据以提高性能。
|
||
|
||
## 创建客户
|
||
|
||
命令:
|
||
|
||
`$ 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'`
|
||
|
||
回复:
|
||
|
||
`成功:已创建客户 17。`
|
||
|
||
## 以 CSV 格式获取客户信息
|
||
|
||
命令:
|
||
|
||
`$ wp wc customer get 17 --user=1 --format=csv`
|
||
|
||
响应:
|
||
|
||
```bash
|
||
字段,值
|
||
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
|
||
```
|
||
|
||
## 在订单 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`
|
||
|
||
回复:
|
||
|
||
```bash
|
||
+---------------+-----------------------+
|
||
| 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`
|
||
|
||
响应:
|
||
|
||
```bash
|
||
+-----------------------------+---------------------+
|
||
| 字段 | 值 |
|
||
+-----------------------------+---------------------+
|
||
| 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`
|
||
|
||
无需额外参数,且仅会运行待审的升级。更新运行完毕后,将显示新版本。 |