WooCommerce: Get List of Downloadable Products (PHP)

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!

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

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

4 thoughts on “WooCommerce: Get List of Downloadable Products (PHP)

  1. 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?

    1. 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!

  2. How is this related to WC_Product::is_downloadable() function ?
    I noticed I got different result on same product.

    1. Hi Adrian! This gives you a list of products, while your function checks if a given product is downloadable

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *