Woocommerce

WooCommerce Downloadable Products: Granting Permissions to Previous Customers

If you’re using WooCommerce to provide downloadable products and add a new download, previous customers do not automatically get access to it as of v3.x.

Here are a couple of options:

Use a Plugin to Force Legacy Behavior

Here is one plugin that reverts the behavior to v2.6.x, but is not recommended due to heavy database usage.

Use MySQL Queries to Grant Access to Previous Customers

Another method to grant access for previous customers to new downloadable items is to run a set of database queries to update their permissions.

This is a one-time process and can handle multiple new files, as well as limit the access to orders after a specific ID number or date.

Here are the steps, tested on WooCommerce v3.2.6:

  1. If you haven’t already, add the new downloadable file(s) to your WooCommerce product(s).
  2. Log in to your MySQL server using a MySQL client (Sequel Pro and phpMyAdmin are two good options) and backup your entire database.
  3. Create a temporary table to hold data; run this SQL query to get it set up. Run this query only once and don’t close your MySQL client when it’s finished.
  4. Get the download_id hash.
    1. In the wp_woocommerce_downloadable_product_permissions table, find a previous order (compare the order_id column against order IDs in your WordPress WooCommerce admin area) and note the download_id value(s) for previous customers.
    2. Place a test order and note the order ID number.
    3. In the wp_woocommerce_downloadable_product_permissions table, find your test order ID in the order_id column and make note of the new download_id value(s) as compared with step A above.
  5. Add all previous customers to the temporary table.
    • Make sure to substitute your WordPress installation’s database prefix in place of the wp_ and set the variables at the top accordingly, then run all these queries. The final query is a sanity check and will show you everything in the temporary table.
    • If you have multiple products/variations/downloads to add, edit the variables as necessary and run all the queries again for each combination to add another batch of customers to the temporary table.
    • Do not close your MySQL client or the temporary table will be dropped along with whatever content is in it. (If you made a mistake and need to empty the table, you can run TRUNCATE temp_wp_woocommerce_downloadable_product_permissions and then re-run these queries as necessary.)
    • When you have added all the product/variation/download combinations to the temporary table, run this query to update the download permissions table for those customers.
    • Double-check that everything on your site is working as it was previously; I recommend taking another backup of your database to be safe. If something happens, you can compare the two backups to see what is different.
    • Close your MySQL client and the temporary table will be dropped by the server.

Now users who have previously purchased a downloadable product will see newly-added downloadable files in their account.

Resources

2 thoughts on “WooCommerce Downloadable Products: Granting Permissions to Previous Customers

  1. I thought this might be my lifesaver as I have just discovered the big gaps in Woocommerce! I might be doing something wrong, but this doesn’t work with products that have previously not had a download attached to the order?

    I film shows and customers purchase a copy of the show to download. However until I edit it, the customer is purchasing a product in advance. There is nothing to download, therefore there are no customer rows in the download permissions table.

    Is there a way around this in your SQL query to add the new download permission id to a product order that has previously not had any any permissions?

  2. I haven’t tested this, but think it will work:

    Add your download to the product and check out so you have a download ID for the product, then add that to previous customers.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.