如何从woo-commerce中获取所有产品? [英] How to get all products from woo-commerce?
问题描述
我设置了 Woo-Commerce,其中包含 1000 多种产品.使用 Woocommerce rest api php 库,我正在尝试获取所有产品.
I have setup Woo-Commerce which have more than 1000 products. Using Woocommerce rest api php library I am trying to get all products.
但它给了我 10 个产品.如果我使用 filter[limit],它会给我大约 400 种产品,不超过这个.
But it gives me 10 products. If I use filter[limit] it gives me around 400 products not more than this.
$res = $wc_api->get_products(array( 'filter[limit]' => 400 ) );
谁能告诉我如何从 woocommerce 获得所有产品?
Can anyone say me how can I get all products from woocommerce?
推荐答案
对于最新版本的 WC API,请使用
For the latest version of the WC API, use
$products = $client->products->get( '', ['filter[limit]' => -1] );
如果它不起作用,请尝试用 posts_per_page 替换限制,如下所示:
If it's not working try replacing the limit with posts_per_page as follows:
'filter[posts_per_page]'=>-1
根据您的服务器规格和产品总数,此类查询可能需要大量内存,因此如果出现任何错误或查询未完成,请确保 php.ini 中的内存限制足够高.
Depending on your server specs and the total number of products this type of query might need a lot of memory so if you get any error or the query doesn't finish be sure that the memory limit in php.ini is high enough.
这篇关于如何从woo-commerce中获取所有产品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!