增加per_page以从woocommerce rest API获取所有订单

时间:2019-04-16 11:03:13

标签: wordpress woocommerce wordpress-rest-api woocommerce-rest-api

我知道会产生什么影响,但我们想从woocommerce rest API获取所有订单。我们有2000多个。我尝试了以下方法,但没有任何作用:

add_filter( 'rest_shop_order_collection_params', function ( $params, WP_Post_Type $post_type ) {
  if ( 'shop_order' === $post_type->name && isset( $params['per_page'] ) ) {
    $params['per_page']['maximum'] = 200;
  }

  return $params;
}, 10, 2 );


add_action( 'rest_shop_order_query', 'shop_order_override_per_page' );
/* 
 * params is the query array passed to WP_Query
*/
function shop_order_override_per_page( $params ) {
  if ( isset( $params ) AND isset( $params[ 'posts_per_page' ] ) ) {
    $params[ 'posts_per_page' ] = 200;
    $params[ 'per_page' ] = 200;
  }
  return $params;
}

以上所有均给出以下错误:

{
    "code": "rest_invalid_param",
    "message": "Invalid parameter(s): per_page",
    "data": {
        "status": 400,
        "params": {
            "per_page": "per_page must be between 1 (inclusive) and 100 (inclusive)"
        }
    }
}

0 个答案:

没有答案