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 at least a default download file to all your customers? Well, the “woocommerce_customer_get_downloadable_products” WooCommerce filter allows us to add files to the list (empty or non empty) of customer downloadable files. Here’s how it’s done!
PHP Snippet: Add a Downloadable File for All Users @ My Account Page
First of all, you’ll need to place your downloadable file on a public URL. I chose the /wp-content folder, the one where also images are stored in WordPress.
Then, define the “product name”, the download button label, and you’re good to go. This will open the file inside the browser (forcing a secure download is much more complicated).
/**
* @snippet Add Download @ My Account Page
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @testedwith WooCommerce 3.8
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_customer_get_downloadable_products', 'bbloomer_add_custom_default_download', 9999, 1 );
function bbloomer_add_custom_default_download( $downloads ) {
$downloads[] = array(
'product_name' => 'Description',
'download_name' => 'Button Label',
'download_url' => '/wp-content/uploads/filename.txt',
);
return $downloads;
}
Works great!
Thanks for another nice and useful snipet.
Regards from Holland
Thank you!
Rodolfo, thanks for the great snippet. It’s a big help. Is there a way to force the download button to open in a new window?
Hi Jonathan, 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!
Hello Rodolfo, thanks for the code, it is very useful to put documentation for all users in general.
Do you know if there is a plugin to insert specific documents in the download area of ββ”my account” of users, so that different documents can be uploaded for each user.
Great!
Don’t know of any plugins to be honest, I’d just customize this same snippet
Hi Rodolfo,
First of all, I want to thank you for all the amazing tips you post on your blog! Everything you do is really very helpful!
In fact, I was using this code on a website, and it was working great in the past months, even a few days ago, but today I noticed that is showing this error on the “my account/user downloads” page:
Notice: Undefined index: product_url in /wp-content/plugins/woocommerce/templates/order/order-downloads.php on line 46
Product Name (in the product name column)
Notice: Undefined index: downloads_remaining in /wp-content/plugins/woocommerce/templates/order/order-downloads.php on line 56 (in the downloads remaining column)
I think it’s due an update of the woocommerce plugin, cause I recently updated to version 5.5.2 (WordPress 5.7.2 & PHP 7.4). The download file still works, but that error message is all over the place. Do you think there is an easy way to fix this issue?
Thanks in advance for your kind response!
Cheers Richard! PHP notices are not major errors. Having said that you could try adding those 2 keys to the array and leave the m with an empty value, and see if that fixes it. Let me know
Hiya
This still works WordPress 5.5 Woocommerce Version 4.5.2
Thank you so much
π
Great!
Thanks for everything, it was very helpful for projects that I had pending and did not come out, and thanks to the information on the page and some comments I was able to solve it.
Cool
Hi Rodolfo,
Thanks for your great trick.
Now I can add my custom files to the customer download page. However, I just wonder how can I add those new files to the beginning of the list of downloadable products? Currently, the new files are added to the last of the list.
Hi Brave, 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!
Hi this is great to know, thank you. My question is: Is there anyway to do this but only for specific users?
Hi Richard, maybe you could use “user roles”. Here’s an example https://www.businessbloomer.com/woocommerce-different-price-user/
hello, is there any way of achieving the following?
in a shop there will be some customers with usernams, eg user1, user 2 etc.
is thee the ability for adding totally different bulk producs (mass photographs) which will different for customers? user1 will be able to buy-download hs own pictures, the same for user 2 etc. At the same time user1 will not be able and mut not be able to see and download photos of user2.
So different downloadable files depending on different username?
hank you
Hey Nick, 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!
For my download website I have put it into operation. Thank you
Great
Hello,
By default, woo-commerce shows the download title on the button, this makes it show in a horrible way, what would it be like if the text “download” was just displayed?
Thank you!
Hi Alvaro, 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!
Hi and thank you for allt the tips you gave! π
I would like to add a target=”_blank” to all downloads links. It’s possible do to it with a custom template of order-downloads.php placed in my own theme but, is it possible to do it withtout the need to override this file?
Thanks
Hi Pascal, 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 can I send files to a specific user?
Javad, 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!
Hi Rodolfo,
Thank you for your post! It’s very close to accomplishing what I need with the exception of being able to check for an active Woocommerce Membership to determine whether or not the logged in customer should see a particular download link on their downloads page.
My particular situation is a little atypical because we are using a custom account registration page to allow customers with a specific invitation code to register for an account that will be manually assigned to a Woocommerce Membership and that membership will provide them with access to downloads and content on the site that most other customers will gain access to by purchasing a product.
Therefore, I would like to be able to check that a customer is enrolled in a particular membership, and if they are, show a specific download link.
Any guidance you can provide would be appreciated.
-Dustin
Hi Dustin, 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!
Hi Rodolfo,
Fantastic snippet – Thx
I need to add more than one file… So how do I add to the array?
Can I pick my own names:
from —–
‘product_name’ => ‘Description’,
‘download_name’ => ‘Button Label’,
‘download_url’ => ‘/wp-content/uploads/filename.txt’,
To —
‘Doc-File1_name’ => ‘Description’,
‘Knap1_name’ => ‘Button Label’,
‘download1_url’ => ‘/wp-content/uploads/filename.txt’,
Do I need to change name for each entry – Like this
‘Doc-File2_name’ => ‘Description’,
‘Knap2_name’ => ‘Button Label’,
‘download2_url’ => ‘/wp-content/uploads/filename.txt’,
and then
‘Doc-File3_name’ => ‘Description’,
‘Knap3_name’ => ‘Button Label’,
‘download3_url’ => ‘/wp-content/uploads/filename.txt’,
Do I need to enter anything in the array [ ] ?? or does the code count entries until it’s finished?
If I need to show an small thumbnail (pdf icon) how can I add that
If I want to add a general video of instruction?
In advanced: Thx
Netzie
Hey Peter:
Hi Rodolfo
I hope you are safe and healthy?
I have revisited this – It keep killing my site? When I add more than one item to download?
Here is my code that work:
Here is the code THAT breaks my site
Thanks for your time and magic helping us all…
Be safe and stay healthy
Netzie
Hey Peter, you’re not closing the $downloads[] arrays before you declare the next one