How to delete uploaded files

Files that customers upload with the file upload field are stored on your server. If customers upload large files, like print files or photos, this can use a lot of disk space over time. This article explains how to remove them.

There are 2 kinds of uploaded files:

  • Files that belong to an order
  • Files that never became part of an order. Files are stored as soon as the customer uploads them, before the product is added to the cart. When a customer changes their mind, or leaves the shop, the file stays on your server.

Delete files that belong to an order

  1. Go to WooCommerce > Orders and open the order.
  2. Below the order items, click Delete files. This button is next to the Download files button.
  3. Confirm. All files uploaded for that order are deleted.

Deleted files can’t be restored. If you still need them, click Download files first to get a ZIP file of all files in the order. After you delete the files, the order still shows the file names, but the links no longer work.

Delete files that don’t belong to an order

Advanced Product Fields has 2 tools to find and remove these files.

Which files are removed?

A file is only removed when all of these are true:

  • The file is older than 30 days.
  • The file is not linked to any order. This includes orders that are pending, cancelled, failed, or in the trash. Only orders you deleted permanently no longer protect their files.

Files that belong to orders are always kept, no matter how old they are.

Step 1: count the files

  1. In your WordPress admin, go to WooCommerce > Status > Tools.
  2. Find Count orphaned APF uploads and click Count files.
  3. You see how many files would be removed and how much space they use. Nothing is deleted yet.

Step 2: delete the files

  1. On the same page, find Delete orphaned APF uploads and click Delete files.
  2. The files are deleted in the background, in small batches. You can leave the page.

Deleted files can’t be restored. Make a backup of the wp-content/uploads/wapf/ folder first if you are not sure.

To follow the progress:

  • WooCommerce > Status > Scheduled Actions: search for wapf_upload_cleanup_batch to see each batch.
  • WooCommerce > Status > Logs: open the log with source wapf-upload-cleanup. It lists every deleted file.

When it’s done, run the count again. It should show 0 files.

There is no automatic cleanup. Run the tools whenever you want to free up space, for example once every few months.

Change the number of days

By default, only files older than 30 days are removed. You can change this with the code snippet below. The minimum is 7 days, so files from carts that are still active are never removed.

Supply your license key to unlock the code

Since this is a custom-coded snippet, please enter your license key so we can verify your purchase.

After you add the snippet, the tool descriptions on the Tools page show the new number of days.

Was this article helpful?

Related Articles