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 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!
After using the snippet below, the “Downloads” section of the WooCommerce My Account page will show a default download file. You can customize the “Description”, “Button Label” and of course the download URL
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).
You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"
Does this snippet (still) work?
Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.
If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)
Need Help with WooCommerce?
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
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.
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.
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?
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
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.
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!
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!
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?
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!
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?
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!
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!
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.
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
Questions? Feedback? Support? Leave your Comment Now! _____
If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. 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 BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)
With 100,000 (and growing) monthly organic sessions, Business Bloomer is the most consistent, most active and most complete WooCommerce development/customization blog.
Of course this website itself uses the WooCommerce plugin, the Storefront theme and runs on a WooCommerce-friendly hosting.
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