I am calling the woocommerce REST api to create an order : /wp-json/wc/v3/orders with quantity as a float value, but the REST api expects an integer quantity value, hence the response errors out.
Response from the POST call below
I tried extending the Base API class in functions.php of child-theme to override the quantity type to float, but thats not working. What ma I missing here?
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();
While I try the same approach to test with a POST on products api, it seems to work. For my testing purpose i changed the regular_price property field to string and it works. Code below for reference.
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();
Why does extending REST Base class for products work & not orders?