Order products and categories by menu_order on WooCommerce REST API

Viewed 344

On WooCommerce Rest API I would like to use orderby query parameter. Because I want to get products and categories ordered by menu_order. But I receive the following error:

{
    "code": "rest_invalid_param",
    "message": "Invalid parameter(s): orderby",
    "data": {
        "status": 400,
        "params": {
            "orderby": "orderby is not one of id, include, name, slug, term_group, description, count."
        }
    }
}

So far I have tried:

add_filter( 'rest_product_collection_params', array( $this, 'filter_add_rest_orderby_params' ), 10, 1 );
add_filter( 'rest_product_cat_collection_params', array( $this, 'filter_add_rest_orderby_params' ), 10, 1 );

function filter_add_rest_orderby_params( $params ) {
    $params['orderby']['enum'][] = 'menu_order';
    return $params;
}

Which does the job for ordering a product but doesn't work for categories. Why is so? Any idea how to achieve ordering by 'menu_order'.

0 Answers
Related