Open arpanet4 opened 3 years ago
Hello @arpanet4,
Thanks for creating the issue. By default woocommerce return 10 results per page. You can change the default option by several ways
Woocommerce
facade$options = [
'per_page' => 50 // Or your desire number
];
$orders = Woocommerce::all('orders', $options);
Order
facade$options = [
'per_page' => 50 // Or your desire number
];
$orders = Order::all($options);
paginate
method$per_page = 50; // Or your desire number
$current_page = 1; // By default 1. That reurns first 1 to 50. If 2 then return 51 to 100 and vice versa
$orders = Order::paginate($per_page, $current_page);
I hope it solves your issues. If you need further query just send details here.
I want to know in this case:
i get the registers by this way :
$results= WCCustomer::all(['per_page'=>100]);
In this case, apparently only it possible get 100 records, if I put a number greater than 100 it shows the next error:
Invalid parameter (s): per_page [rest_invalid_param]
How can i get all the records?
I want to know in this case: i get the registers by this way :
$results= WCCustomer::all(['per_page'=>100]);
In this case, apparently only it possible get 100 records, if I put a number greater than 100 it shows the next error:Invalid parameter (s): per_page [rest_invalid_param]
How can i get all the records?
Any solution here?
Hello @CRMSoluciones @vlkf,
Where do you get WCCustomer
? Please check the original doc https://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties
Hello @CRMSoluciones @vlkf,
Where do you get
WCCustomer
? Please check the original doc https://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties
It's not working with Product facade also.
Product::all(['per_page'=> 200]);
Gives the error ->
Exception (1) Error: Invalid parameter(s): per_page [rest_invalid_param]
Hello @CRMSoluciones @vlkf, Where do you get
WCCustomer
? Please check the original doc https://woocommerce.github.io/woocommerce-rest-api-docs/#order-propertiesIt's not working with Product facade also.
Product::all(['per_page'=> 200]);
Gives the error ->Exception (1) Error: Invalid parameter(s): per_page [rest_invalid_param]
I am having the same issue! So I kept digging and found the reason why it's failing!
I wish the maintainer show this message instead of just:
Exception (1) Error: Invalid parameter(s): per_page [rest_invalid_param]
You can override it on the API server side:
add_action( 'rest_product_query', function( $params ) { if ( isset( $params ) AND isset( $params[ 'posts_per_page' ] ) ) { $params[ 'posts_per_page' ] = "200"; } return $params; });
However, this will most likely degrade the responsiveness of the remote WC API server! especially if used as normal website. Maybe best bet is to use pagination for > 100 products/orders!
Thanks, @EazyServer for commenting. You are right the per_page
value must be between 1
to 100
. You must allow your wordpress server so that it can support greater than 100.
Sorry to ask but shouldn't this Product::all() method auto-paginate?
I've just come accross the same need to get "all" categories and this helped me solve my problem. I didn't want to change Wordpress REST API defaults.
Appreciate the method below doesn't use the Order facade/model in the thread but the principle applies nevertheless.
Hopefully helps the next person!
protected function getWooCommerceCategories(): array
{
$categories = [];
$currentPage = 1;
try {
do {
$response = WooCommerce::all('products/categories', [
'per_page' => 50,
'page' => $currentPage,
]);
$categories = array_merge($categories, $response);
$currentPage++;
} while (! empty($response));
} catch (\Exception $e) {
Log::error($e->getMessage());
}
return $categories;
}
Hello, in the last version only get 10 registers.
For example in: $orders = Order::all();
Thanks.