admin管理员组文章数量:1331230
When I try to fetch products using the official REST API, returned product
contains the a property named images
which is an array and contains the URL to image of product.
But when I fetch using this method, it fetches other details but not the image.
$productsQuery= wc_get_products(array(
'limit' => 10,
'status' => 'publish',
));
$products = array();
foreach ($productsQuery as $product) {
$products[] = $product->get_data();
}
return new WP_REST_Response($products, 200);
how can I make this to return the images
property as well.
When I try to fetch products using the official REST API, returned product
contains the a property named images
which is an array and contains the URL to image of product.
But when I fetch using this method, it fetches other details but not the image.
$productsQuery= wc_get_products(array(
'limit' => 10,
'status' => 'publish',
));
$products = array();
foreach ($productsQuery as $product) {
$products[] = $product->get_data();
}
return new WP_REST_Response($products, 200);
how can I make this to return the images
property as well.
1 Answer
Reset to default 2The WC_Product object has an image_id
(string) and an gallery_image_ids
(array) attribute for product image and product's gallery images. Both of them are attachment ids, so you should get the image src from it's attachment id with the wp_get_attachment_image_url()
method and add it to your $products
array.
本文标签: woocommerce offtopicwcgetproducts() not return the images details
版权声明:本文标题:woocommerce offtopic - wc_get_products() not return the images details 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742233781a2437699.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论