WooCommerce: Get List of Downloadable Products

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 CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.7
 * @community     https://businessbloomer.com/club/
 */

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

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

  • WooCommerce: Add a Custom Download File @ My Account
    If you sell no downloadable products, the Downloads section of the WooCommerce My Account page will always be empty (in this case, you should completely hide the My Account Download tab). Besides, if you do sell downloadable products but customers never purchased such items, the same will happen. So, what if you wanted to grant […]
  • WooCommerce: Fix “Sorry, This File Type Is Not Permitted for Security Reasons” For Downloadable Products
    In WordPress, you get the “Sorry, This File Type Is Not Permitted for Security Reasons” error when you try to upload certain files to the Media library. Similarly, in WooCommerce you may get the same error when you try to upload a downloadable product download files. Why is that? Well, by default WordPress only allows […]
  • WooCommerce: Rename Downloads Table Column Title @ My Account
    The WooCommerce My Account > Downloads endpoint features a table which lists the available downloads. This table has 4 default columns: Product, Downloads remaining, Expires, Download (as you can see from the screenshot below). Now, it’s very likely you may want to rename these headings into something more readable or understandable. On top of that, […]

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

2 thoughts on “WooCommerce: Get List of Downloadable Products

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