woocommerce - 为 /orders 端点扩展 Woocommerce Rest API 类和更改架构
问题描述
我正在调用 woocommerce REST api 来创建订单: /wp-json/wc/v3/orders
数量为浮点值,但 REST api 需要一个整数数量值,因此响应错误。
来自下面的 POST 调用的响应
我尝试在子主题的functions.php中扩展Base API类以将数量类型覆盖为浮动,但这不起作用。我在这里想念什么?
class CUSTOM_WC_REST_Orders_Controller extends WC_REST_Orders_Controller
{
public function get_item_schema()
{
$schema = parent::get_item_schema();
$schema['properties']['line_items']['items']['properties']['quantity']['type'] = 'float';
return $schema;
}
}
new CUSTOM_WC_REST_Orders_Controller();
虽然我尝试使用相同的方法在产品 api 上使用 POST 进行测试,但它似乎有效。为了我的测试目的,我将 regular_price 属性字段更改为字符串,它可以工作。下面的代码供参考。
class CUSTOM_WC_REST_Product_Controller extends WC_REST_Products_Controller
{
public function get_item_schema()
{
$schema = parent::get_item_schema();
$schema["properties"]["regular_price"]["type"] = "string";
return $schema;
}
}
new CUSTOM_WC_REST_Product_Controller();
为什么为产品扩展 REST 基类而不是订单?
解决方案
推荐阅读
- gradle - 使用 BasicAuthentication 的 Maven 存储库的身份验证失败的快速失败 Gradle
- react-native - 可以在前端使用 Firebase Auth SDK 进行移动应用身份验证吗?
- python - 如何处理消息框上的“删除窗口”协议-Python tkinter
- windows-10 - Windows 10 中基于 WPA2 企业证书的日志记录问题
- python - 自动前后移动矩形
- excel - 使用来自多个工作表的条件将项目从多个范围添加到组合框
- python - TensorFlow 在 text_dataset_from_directory 之后重塑
- selenium-chromedriver - SpecFlow - 参数类型“System.MarshalByRefObject”无法转换为参数类型“TechTalk.SpecRun.Common.Logging.ITestLogger”
- node.js - 时间限制增加时如何自动将数据插入MongoDB
- string - RASA:如果示例包含数字作为数字序列,则检测到错误的意图和实体