Home » WooCommerce: Add a Custom Download File @ My Account

WooCommerce: Add a Custom Download File @ My Account

by Tutor Aspire

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 tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 3.8
 * @donate $9     https://tutoraspire.com
 */

add_filter( 'woocommerce_customer_get_downloadable_products', 'tutoraspire_add_custom_default_download', 9999, 1 );

function tutoraspire_add_custom_default_download( $downloads ) {
$downloads[] = array(
'product_name' => 'Description',
'download_name' => 'Button Label',
'download_url' => '/wp-content/uploads/filename.txt',
);
return $downloads;
}

You may also like