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

plugin development - Getting products information, in woocommerce based on products ID

programmeradmin0浏览0评论

I have some ids like this

$products = (1,2,3,4);

I need to query woocommerce database to get info all products with that ids something like when im querying based on cateogory

$products = wc_get_products(array(
    'category' => array('Test'),
));

Is possible to get based on ID, thanks?

I have some ids like this

$products = (1,2,3,4);

I need to query woocommerce database to get info all products with that ids something like when im querying based on cateogory

$products = wc_get_products(array(
    'category' => array('Test'),
));

Is possible to get based on ID, thanks?

Share Improve this question asked May 27, 2020 at 8:52 Miomir DancevicMiomir Dancevic 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

You can get the WC_Product object for a product ID with the wc_get_product() function. So by using array_map() you can get the product data for those IDs like this:

$product_ids = [ 1, 2, 3, 4 ];
$products    = array_map( 'wc_get_product', $product_ids );

foreach ( $products as $product ) {
    echo $product->get_name();
}
发布评论

评论列表(0)

  1. 暂无评论