Home » WooCommerce: Get List of Downloadable Products

WooCommerce: Get List of Downloadable Products

by adminkys

When you’re doing custom PHP work, this snippet will come handy. It’s a quick way to get a sublist 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, translated in English, means they are “downloadable”).

Of course, you can edit this snippet to get any sublist of product IDs, for example in stock products, custom field value products, below/above sales number, and so on. Whatever is stored as a custom field can be used. Enjoy!

Here’s the PHP array of downloadable product IDs after using the snippet below

PHP Snippet: Get List of WooCommerce Downloadable Products

 * @snippet       Get WooCommerce Downloadable Products
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 3.7
 * @donate $9     https://www.tutoraspire.com

// Get downloadable products
$product_ids = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'meta_query' => array( array(
'key' => '_downloadable',
'value' => 'yes',
'compare' => '=',

// Print array on screen
print_r( $product_ids );

You may also like