最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I get all the woocommerce api orders

programmeradmin0浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 3 years ago.

Improve this question

When I do a get with my postman to

It only returns 10 results, and in woocommerce I have 2000 orders How can I get those 2000 orders?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 3 years ago.

Improve this question

When I do a get with my postman to

https://page.com/wp-json/wc/v3/orders

It only returns 10 results, and in woocommerce I have 2000 orders How can I get those 2000 orders?

Share Improve this question edited Dec 4, 2020 at 15:48 Gerardo Marroquin asked Dec 4, 2020 at 15:30 Gerardo MarroquinGerardo Marroquin 1131 silver badge6 bronze badges 1
  • If the standard REST API pagination does not work for you then you will need to ask their support or ask in one of their communities, 3rd party plugin dev support is off-topic here – Tom J Nowell Commented Jan 26, 2022 at 10:47
Add a comment  | 

2 Answers 2

Reset to default 2

By default, that API endpoint is paged and the amount per_page is set to 10. You can see all the defaults for that endpoint here https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-orders

If this endpoint works like WP_Query then you'll need to set the per_page parameter to -1. Otherwise you'll need to make multiple requests, incrementing the page number each time until you've received all the orders

this will surely show all orders

  enter code here
  const WooCommerceRestApi = require("@woocommerce/woocommerce-rest-api").default;

const api = new WooCommerceRestApi({
  url: process.env.NEXT_PUBLIC_WORDPRESS_SITE_URL,
  consumerKey: process.env.CONSUMER_KEY,
  consumerSecret: process.env.CONSUMER_SECRET,
  version: "wc/v3"
});
export default async function handler(req, res){
  const responseData = {
      success:false,
      orders: []
  }

  const { perPage} = req?.query ?? {};
  try {
      const {data} = await api.get(
          'orders',
          {
              per_page:perPage||100


          }
      );
      responseData.success = true;
      responseData.orders = data;
      res.json( responseData);
  } catch ( error ){
      responseData.error = error.message;
      res.status(500).json(responseData);
  }
}


发布评论

评论列表(0)

  1. 暂无评论