如何解决扩展Woocommerce Rest API类并更改/ orders端点的模式
我正在调用woocommerce REST api创建一个数量为浮点值的订单 /wp-json/wc/v3/orders
,但是REST api需要一个整数值,因此响应错误。
Response from the POST call below
我尝试在child-theme的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 Base类而不是订单有效?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。