Woocommerce 扩展RESTAPI类&;更改/订单终结点的架构

Woocommerce 扩展RESTAPI类&;更改/订单终结点的架构,woocommerce,woocommerce-rest-api,Woocommerce,Woocommerce Rest Api,我调用woocommerce REST api来创建一个订单:/wp json/wc/v3/orders,数量作为浮点值,但REST api需要一个整数数量值,因此响应会出错。 我尝试扩展子主题的functions.php中的基本API类,以将quantity类型重写为float,但这不起作用。我错过了什么 class CUSTOM_WC_REST_Orders_Controller extends WC_REST_Orders_Controller { public functio

我调用woocommerce REST api来创建一个订单:
/wp json/wc/v3/orders
,数量作为浮点值,但REST api需要一个整数数量值,因此响应会出错。

我尝试扩展子主题的functions.php中的基本API类,以将quantity类型重写为float,但这不起作用。我错过了什么

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,但它似乎是可行的。出于测试目的,我将常规的_price属性字段改为string,它可以工作。以下代码供参考

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基类有效&而不是订单