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

I have some ids like this $products = (1,2,3,4);I need to query woocommerce database to get info all products with that

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();
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742397902a4436317.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信