跳到主要内容

WooCommerce 核心 API 中的关键流程

在我们的文档中,我们已经确定了 WooCommerce 核心 API 中的关键用户流程。这些流程是我们测试工作的指南,帮助我们集中精力在最重要的方面。它们也为评估修改的影响以及确定问题优先级提供了宝贵的见解。

需要注意的是,这些流程是动态的,会随着平台的发展而不断演变。它们会定期进行更新、添加和重新排序,以适应我们系统不断变化的需求。

产品

路由流程名称接口测试文件
产品可以查看所有产品/wp-json/wc/v3/productstests/api-core-tests/tests/products/product-list.test.js
产品可以搜索产品/wp-json/wc/v3/productstests/api-core-tests/tests/products/product-list.test.js
产品可以添加一个简单产品/wp-json/wc/v3/productstests/api-core-tests/tests/products/products-crud.test.js
产品可以添加一个可变产品/wp-json/wc/v3/productstests/api-core-tests/tests/products/products-crud.test.js
产品可以添加一个虚拟产品/wp-json/wc/v3/productstests/api-core-tests/tests/products/products-crud.test.js
产品可以查看单个产品/wp-json/wc/v3/products/{id}tests/api-core-tests/tests/products/products-crud.test.js
产品可以更新产品/wp-json/wc/v3/products/{id}tests/api-core-tests/tests/products/products-crud.test.js
产品可以删除产品/wp-json/wc/v3/products/{id}tests/api-core-tests/tests/products/products-crud.test.js

订单

路由流程名称接口地址测试文件
订单可以创建订单/wp-json/wc/v3/orderstests/api-core-tests/tests/orders/orders-crud.test.js
订单可以查看单个订单/wp-json/wc/v3/orders/{id}tests/api-core-tests/tests/orders/orders-crud.test.js
订单可以更新订单/wp-json/wc/v3/orders/{id}tests/api-core-tests/tests/orders/orders-crud.test.js
订单可以删除订单/wp-json/wc/v3/orders/{id}tests/api-core-tests/tests/orders/orders-crud.test.js
订单可以查看所有订单/wp-json/wc/v3/orderstests/api-core-tests/tests/orders/orders.test.js
订单可以搜索订单/wp-json/wc/v3/orderstests/api-core-tests/tests/orders/order-search.test.js
订单可以新增复杂订单 - 包含多种产品类型和税类/wp-json/wc/v3/orderstests/api-core-tests/tests/orders/order-complex.test.js

退款

路由流程名称接口地址测试文件
退款可以退款订单/wp-json/wc/v3/orders/{id}/refundstests/api-core-tests/tests/refunds/refund.test.js

优惠券

路由流程名称接口地址测试文件
优惠券可以创建优惠券/wp-json/wc/v3/couponstests/api-core-tests/tests/coupons/coupons.test.js
优惠券可以更新优惠券/wp-json/wc/v3/coupons/{id}tests/api-core-tests/tests/coupons/coupons.test.js
优惠券可以删除优惠券/wp-json/wc/v3/coupons/{id}tests/api-core-tests/tests/coupons/coupons.test.js
优惠券可以将优惠券添加到订单/wp-json/wc/v3/orders/{id}/couponstests/api-core-tests/tests/coupons/coupons.test.js

配送

路线流程名称接口测试文件
配送区域可以创建配送区域/wp-json/wc/v3/shipping/zonestests/api-core-tests/tests/shipping/shipping-zones.test.js
配送方式可以为配送区域创建配送方式/wp-json/wc/v3/shipping/zones/{id}/methodsn/a
配送类型可以创建产品配送类型/wp-json/wc/v3/products/shipping_classestests/api-core-tests/tests/products/products-crud.test.js

Shipping Classes

This document describes how to use the API to manage Shipping Classes.

Creating a Shipping Class

To create a new Shipping Class, you can use the following API endpoint:

POST /wp-json/wc/v3/products/shipping_classes

The request body should contain the following parameters:

  • name: The name of the Shipping Class.
  • description: A description of the Shipping Class.
  • method_id: The ID of the Shipping Method to associate with the Shipping Class.

For example:

{
"name": "Expedited Shipping",
"description": "Faster shipping option",
"method_id": 123
}

Updating a Shipping Class

To update an existing Shipping Class, you can use the following API endpoint:

PUT /wp-json/wc/v3/products/shipping_classes/%d

where %d is the ID of the Shipping Class you want to update.

The request body should contain the parameters you want to update.

Deleting a Shipping Class

To delete a Shipping Class, you can use the following API endpoint:

DELETE /wp-json/wc/v3/products/shipping_classes/%d

where %d is the ID of the Shipping Class you want to delete.

Example Usage

Here is an example of how to create a new Shipping Class using the API:

import requests

url = "https://example.com/wp-json/wc/v3/products/shipping_classes"
headers = {"Content-Type": "application/json"}
data = {
"name": "Expedited Shipping",
"description": "Faster shipping option",
"method_id": 123
}

response = requests.post(url, headers=headers, json=data)

if response.status_code == 201:
print("Shipping Class created successfully!")
print(response.json())
else:
print("Error creating Shipping Class:")
print(response.status_code)
print(response.text)

This example uses the requests library to make an HTTP POST request to the API endpoint. The headers dictionary specifies the Content-Type header, which indicates that the request body is in JSON format. The data dictionary contains the parameters for the new Shipping Class.

The response from the API is checked to see if it was successful. If the status code is 201 (Created), then the Shipping Class was created successfully. The response body contains the details of the new Shipping Class. If the status code is not 201, then an error occurred, and the error message is printed.

Important Considerations

  • Make sure you have the necessary permissions to create, update, and delete Shipping Classes.
  • The API may require authentication.
  • The API may have rate limits.
  • Always handle errors gracefully.

This document provides a basic overview of how to use the API to manage Shipping Classes. For more information, please refer to the API documentation.

Testing

The following TEST cases are available for verifying the functionality of the Shipping Classes API:

  • Can create a new Shipping Class.
  • Can update an existing Shipping Class.
  • Can delete a Shipping Class.
  • Can retrieve a list of Shipping Classes.

These TEST cases can be run using the tests/api-core-tests/tests/products/products-crud.test.js File.

Troubleshooting

If you are having trouble using the API, please consult the following resources:

  • The API documentation
  • The online forums
  • The support team

If you are still unable to resolve the issue, please contact the support team for assistance.

Error Codes

The following error codes may be returned by the API:

  • 400 Bad Request: The request was invalid.
  • 401 Unauthorized: You are not authorized to perform this action.
  • 403 Forbidden: You do not have permission to perform this action.
  • 404 Not Found: The resource you are trying to access does not exist.
  • 500 Internal Server Error: An unexpected error occurred on the server.

Pro features may require a paid subscription.

Shipping Zones

You can create Shipping Zones to define different shipping rates for different regions. Each Shipping Zone can have multiple Shipping Methods associated with it.

Shipping Methods

Shipping Methods define how products are shipped. You can create different Shipping Methods for different Shipping Classes and Shipping Zones.

Core functionality is available in the free version.

Low latency is important for a good user experience.

In some cases, you may need to manually configure the Shipping Classes.

This is one example.

Or you can use a different approach.

The value is n/a.

The Name of the Product is required.

The Method is not supported.

The Class is not defined.