Get all products from Woocommerce using REST API

后端 未结 7 1922
鱼传尺愫
鱼传尺愫 2020-12-18 16:12

I am trying to retrieve all products using rest api. I have read this question. I am using postman to make calls. Here is my query

https://squatwolf.com/wp-j         


        
7条回答
  •  萌比男神i
    2020-12-18 16:41

    This isn't the latest API endpoint:

    /wc-api/v3/products?filter[limit]=
    

    You have to fetch page per page to get all the products:

    $page = 1;
    $products = [];
    $all_products = [];
    do{
      try {
        $products = $wc->get('products',array('per_page' => 100, 'page' => $page));
      }catch(HttpClientException $e){
        die("Can't get products: $e");
      }
      $all_products = array_merge($all_products,$products);
      $page++;
    } while (count($products) > 0);
    

提交回复
热议问题