WooCommerce allows you to sell different kinds of products. In this post I we will cover virtual downloadable products. The reason that those products are super cool is because they are virtual.

You don’t have to think about shipping stuff which opens the opportunity to automate things.

When you automate things you (or your employees) don’t have to be the bottleneck in your business.

To add a virtual you need to go to

WP Admin > Products > Add New

Fill out all the fields that make sense such as Title, Description, Regular Price and then check the boxes for:

[X] Virtual & [X] Downloadable and then click on Add or Update button (in the sidebar).

The image below shows the WooCommerce Add/Update product screen.

WooCommerce Add/Update product screen.

WooCommerce Add/Update product screen.

If you have hundreds of downloadable products and especially if you have multiple variations per product it may be hard or time consuming to set the download limits manually.

For this reason we recommend hooking into WooCommerce’s system programmatically so you set the limits and they will apply to all products. Later if you change your mind to increase the limits e.g. allow more downloads or allow the download expiration date, you’ll have to update the limits on one spot and the change will apply to all products. This applies to new orders only though.

If you need to Reset the download limits for a specific customer or for all of them feel free to check out our  Orbisius Reset Download Limits for WooCommerce plugin.

How to use this

 

How to use the code. You need to paste the code into your functions.php right after the opening <?php tag on a new line. If you use a custom plugin you can paste the code there. That would be a better approach because using a custom plugin will make sure that the functionality stays even if you change your theme.

The following code works for simple virtual downloadable products.

// 3 downloads
add_filter('woocommerce_product_get_download_limit', function ($val, $obj) {
	return $val <= 0 ? 3 : $val;
}, 30, 2);

// 3 days
add_filter('woocommerce_product_get_download_expiry', function ($val, $obj) {
	return $val <= 0 ? 3 : $val;
}, 30, 2);

If you have variable virtual downloadable products for example you sell the same product with different licenses. Another example would be if you're selling WordPress plugins or themes that people can use or One site, 3 sites or Unlimited sites.

The following code works for variable virtual downloadable products.

// 3 downloads
add_filter('woocommerce_product_variation_get_download_limit', function ($val, $obj) {
	return $val <= 0 ? 3 : $val;
}, 30, 2);

// 3 days
add_filter('woocommerce_product_variation_get_download_expiry', function ($val, $obj) {
	return $val <= 0 ? 3 : $val;
}, 30, 2);

If you sell both types of products you can use both code snippets.

 

If your web hosting is running php <= 5.4 you can use these snippets instead.

 

Related links

Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer