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 badge1 Answer
Reset to default 0You 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();
}