Business Bloomer
  • About
  • WooCommerce Blog
  • Online Courses
  • Login
  • 0
  • About
  • WooCommerce Blog
  • Online Courses
  • Login
  • 0

WooCommerce: Add a Custom Download File @ My Account

> Published: Jan 2020
> Blog Category: WooCommerce Tips
> Blog Tags: Downloadable, My Account
> Blog Comments: 32 Comments
Tweet

Join 17,000+ WooWeekly subscribers

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        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.8
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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;
}

Related posts:

  1. WooCommerce: Add New Tab @ My Account Page
  2. WooCommerce: Add First & Last Name to My Account Register Form
  3. WooCommerce: Add Select Field to “My Account” Register Form
  4. WooCommerce: Hide or Rename a My Account Tab
  5. WooCommerce: How to Merge My Account Tabs
  6. WooCommerce: Add Privacy Policy Consent @ My Account Registration
  7. WooCommerce: Separate Login, Registration, My Account Pages
  8. WooCommerce: Allow Users to Edit Processing Orders
  9. WooCommerce: Deny Automatic Login Upon Registration @ My Account
  10. WooCommerce: Rename “My Account” If Logged Out @ Nav Menu

Where to add this snippet?

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.

Follow @rmelogli
Category: WooCommerce Tips
Tags: Downloadable, My Account

Post navigation

Previous post: WooCommerce: How to Calculate Product Prices with Custom Formulas
Next post: WooCommerce: Full Width Featured Image @ Single Product Page

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? 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 :)

Cancel reply

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

Recent Posts
  • WooCommerce: Redirect Product Category Pages
  • WooCommerce: Close Button @ WooCommerce Checkout Notices
  • WooCommerce: Related Products Custom Heading & Subheading
  • WooCommerce: Display Stock Status For External Products
  • WooCommerce: Display Product Grid @ Order Emails e.g. Related Products
About Business Bloomer

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.

Join 75,000+ Monthly Readers & 16,500+ Subscribers.

Become a Business Bloomer Supporter.

Join BloomerArmada and become an Official Business Bloomer Supporter:
easy-peasy, and lots of perks for you.
See your Benefits →
Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting
Latest Articles
  • WooCommerce: Redirect Product Category Pages
  • WooCommerce: Close Button @ WooCommerce Checkout Notices
  • WooCommerce: Related Products Custom Heading & Subheading
  • WooCommerce: Display Stock Status For External Products
  • WooCommerce: Display Product Grid @ Order Emails e.g. Related Products
Latest Comments
  • Rodolfo Melogli on WooCommerce: Get Cart Info (total, items, etc) from $cart Object
  • Rodolfo Melogli on WooCommerce: Hide Checkout Fields if Virtual Product @ Cart
  • Rodolfo Melogli on WooCommerce: Separate Login, Registration, My Account Pages
  • Rodolfo Melogli on WooCommerce: Add to Cart Quantity Plus & Minus Buttons
Find Out More
  • Become a WooCommerce Expert
  • WooCommerce Blog
  • WooCommerce Online Courses
  • WooCommerce Weekly
  • Bloomer Armada
  • Affiliate Program
  • 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:

Email: [email protected]

Twitter: @rmelogli

Hire me by the hour: Get Quote »

VisaMastercardAmexPayPal Acceptance Mark
Business Bloomer © 2011-2023 - Terms of Use - Privacy Policy