When you’re doing custom PHP work, this snippet will come in handy. It’s a quick way to get a sub-list of product IDs based on product meta criteria – in this case we’ll get a list of products that have “_downloadable” set to “yes” (which, in plain English, means they are “downloadable“).
Of course, you can use wc_get_products to get any sub-list of product IDs, for example in stock products, products by custom field value, products by category, products by tax class, and so on. Enjoy!
PHP Snippet: Get List of WooCommerce Downloadable Products
/**
* @snippet Get WooCommerce Downloadable Products IDs
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 8
* @community https://businessbloomer.com/club/
*/
$product_ids = wc_get_products( array(
'downloadable' => 'true',
'limit' => -1,
'status' => 'publish',
'return' => 'ids',
));
// Print array on screen
print_r( $product_ids );
I have a question somewhat related to this. I want to display the downloadable products on a custom woocommerce endpoint, but only for a specific variable product. So, I have a product with different versions that a user may have multiple versions of. How would I go about doing something like this?
Aaron, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
How is this related to WC_Product::is_downloadable() function ?
I noticed I got different result on same product.
Hi Adrian! This gives you a list of products, while your function checks if a given product is downloadable