Black Friday 2026: up to 50% off today See Deals Dismiss

Reserve Your Free Seat for Our Next WooCommerce Class! Search
Business Bloomer
  • Join
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • 0
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • Search
  • Contact
  • Cart
WooCommerce Code Snippets Downloadable My Account

WooCommerce: Add a Custom Download File @ My Account

Last Revised: Jan 2020

STAY UPDATED

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

/**
 * @snippet       Add Download @ My Account Page
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @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;
}

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: Separate Login, Registration, My Account Pages
    There are times when you need to send logged out customers to a Login page and unregistered customers to a standalone Register page. As you…
  • WooCommerce: Add New Tab @ My Account Page
    One of the features of Business Bloomer Club is the provision of Premium WooCommerce Q&A Support to supporters who enroll. So, how to add an…
  • WooCommerce: How To Make A Website GDPR Compliant? (12 Steps)
    Ok, we all know that the EU General Data Protection Regulation (GDPR) will come into force on the 25th May 2018. So the main question…
  • WooCommerce Visual Hook Guide: My Account Pages
    Hey WooCustomizers, the Visual Hook Guide is back πŸ™‚ In this episode, I’ve created a visual HTML hook guide for the WooCommerce Account Pages (there…
  • WooCommerce: Add First & Last Name to My Account Register Form
    Here’s yet another useful PHP snippet – and a mini-plugin alternative with super simple settings – that adds the Billing First Name and Billing Last…

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

32 thoughts on “WooCommerce: Add a Custom Download File @ My Account”

  1. Benjamin
    November 25, 2022

    Works great!
    Thanks for another nice and useful snipet.
    Regards from Holland

    Reply
    1. Rodolfo Melogli
      November 25, 2022

      Thank you!

      Reply
  2. Jonathan
    October 19, 2022

    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?

    Reply
    1. Rodolfo Melogli
      October 26, 2022

      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!

      Reply
  3. Diego
    June 14, 2022

    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.

    Reply
    1. Rodolfo Melogli
      June 20, 2022

      Great!

      Don’t know of any plugins to be honest, I’d just customize this same snippet

      Reply
  4. Richard Nun
    July 25, 2021

    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!

    Reply
    1. Rodolfo Melogli
      August 19, 2021

      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

      Reply
  5. Jen
    October 6, 2020

    Hiya
    This still works WordPress 5.5 Woocommerce Version 4.5.2
    Thank you so much
    πŸ™‚

    Reply
    1. Rodolfo Melogli
      October 16, 2020

      Great!

      Reply
  6. jose
    September 19, 2020

    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.

    Reply
    1. Rodolfo Melogli
      September 21, 2020

      Cool

      Reply
  7. Brave
    September 7, 2020

    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.

    Reply
    1. Rodolfo Melogli
      September 10, 2020

      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!

      Reply
  8. Richard
    June 28, 2020

    Hi this is great to know, thank you. My question is: Is there anyway to do this but only for specific users?

    Reply
    1. Rodolfo Melogli
      June 28, 2020

      Hi Richard, maybe you could use “user roles”. Here’s an example https://www.businessbloomer.com/woocommerce-different-price-user/

      Reply
  9. nick
    June 2, 2020

    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

    Reply
    1. Rodolfo Melogli
      June 15, 2020

      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!

      Reply
  10. DiseΓ±o web Sevilla
    May 27, 2020

    For my download website I have put it into operation. Thank you

    Reply
    1. Rodolfo Melogli
      June 1, 2020

      Great

      Reply
  11. Alvaro Guerra
    May 5, 2020

    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!

    Reply
    1. Rodolfo Melogli
      May 13, 2020

      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!

      Reply
  12. Pascal
    April 23, 2020

    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

    Reply
    1. Rodolfo Melogli
      April 23, 2020

      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!

      Reply
  13. javad
    March 7, 2020

    How can I send files to a specific user?

    Reply
    1. Rodolfo Melogli
      March 9, 2020

      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!

      Reply
  14. Dustin
    March 4, 2020

    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

    Reply
    1. Rodolfo Melogli
      March 9, 2020

      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!

      Reply
  15. Peter Netz Lassen
    January 23, 2020

    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

    Reply
    1. Rodolfo Melogli
      January 25, 2020

      Hey Peter:

      $downloads[] = array(
      	'product_name' => 'Enter Here Description 1',
      	'download_name' => 'Enter Here Button Label 1',
      	'download_url' => 'Enter Here URL 1',
      $downloads[] = array(
      	'product_name' => 'Enter Here Description 2',
      	'download_name' => 'Enter Here Button Label 2',
      	'download_url' => 'Enter Here URL 2',
      );
      
      Reply
      1. Peter
        April 14, 2020

        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:

        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' => 'Shake Opskrifter',
              'download_name' => 'Download Samling',
              'download_url' => '/wp-content/uploads/2015/09/protein-shake-opskrifter.pdf',
           );
           return $downloads;
        }
        

        Here is the code THAT breaks my site

        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' => 'Shake Opskrifter',
              'download_name' => 'Download Samling',
             'download_url' => '/wp-content/uploads/2015/09/protein-shake-opskrifter.pdf',
        $downloads[] = array(
           'product_name' => 'Shake 2',
           'download_name' => 'Enter Here Button Label 1',
           'download_url' => '#',
        $downloads[] = array(
           'product_name' => 'Enter Here Description 2',
           'download_name' => 'Enter Here Button Label 2',
           'download_url' => '#',
           );
           return $downloads;
        }
        
        

        Thanks for your time and magic helping us all…

        Be safe and stay healthy

        Netzie

        Reply
        1. Rodolfo Melogli
          April 16, 2020

          Hey Peter, you’re not closing the $downloads[] arrays before you declare the next one

          Reply
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!

Cancel reply

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


Search WooCommerce Tips

Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting

Recent Articles

  • WooCommerce: Simple Price Including/Excluding Tax Switcher
  • WooCommerce: Refund Request Button @ My Account
  • WooCommerce: Show or Hide Bank Accounts Based On Order
  • WooCommerce: Save Order Currency Exchange Rate
  • WooCommerce: Get Orders Containing a Specific Product

Latest Comments

  1. Rodolfo Melogli on WooCommerce: “Inconsistent tax settings” Error
  2. ARNo on WooCommerce: Attach Files (PDF, etc.) To Emails
  3. Rodolfo Melogli on WooCommerce: Only Allow 1 Product in the Cart

Find Out More

  • Become a WooCommerce Expert
  • Business Bloomer Club
  • WooCommerce Blog
  • WooCommerce Weekly
  • Contact

Contact Info

Ciao! I'm Rodolfo Melogli, an Italian Civil Engineer who has turned into an international WooCommerce expert. You can contact me here:

Twitter: @rmelogli

Get in touch: Contact Page

Business Bloomer © 2011-2025 - VAT IT02722220817 - Terms of Use - Privacy Policy

Cart reminder?

x