WooCommerce is undoubtedly a very famous plugin, to sell products from your WordPress e-stores. It supports the selling of physical, as well as downloadable or virtual products. Recently, while trying to set up a store with WooCommerce to sell digital products, for a client project, we found that the download links for products were not generated, even after the payment was successful.
The Ideal Scenario
Generally what should happen is, if a customer comes to your site, selects a downloadable product, and purchases it, the email that goes to the client from WooCommerce, should contain the link to download the purchased product. Not only this, after being redirected to your site upon making successful payment, the download link should be shown to user on the website, so that the user can directly download the product.
But in our case, none of this was happening. The download link was neither present in the email, nor available on the site.
While debugging the issue, we found out the cause. The WooCommerce table which stores user downloading permissions, ‘woocommerce_downloadable_product_permissions’, was not created. The download links, shown to the user, are generated using this table.
We would like to specify here, that the solution provided by this article, has been tested only for a Single site WordPress installation and not for WordPress Multisite (WPMU/WPMS) installations. Most Importantly make sure you BACKUP your entire DATABASE, before performing the following database related operations. Hence you can always revert to it in case anything is messed up.
A Note About WordPress Database Table Name Prefix
As a good practice, all plugins when creating their own database tables, use the WordPress database prefix, specified in the wp-config.php. Following the same rule, WooCommerce also generates all tables with the mentioned prefix. Hence, if database prefix mentioned in wp-config.php is ‘wp_’, then the table created by WooCommerce will be named, wp_woocommerce_downloadable_product_permissions.
To find out your database prefix, open up wp-config.php file present in the root directory of WordPress and search for the line ‘$table_prefix = ‘. Value assigned to the variable table_prefix is your database prefix.
How did the Prefix Affect Our Use Case?
Coming back to the topic, WooCommerce or any other plugin which generates own tables will fail to create tables if the length of table names exceeds 64, because 64 is the maximum length for table names as specified by MySQL.
In our case, database prefix set by the client, itself was greater than 20 characters! Hence, the entire table name exceeded 64 characters and WooCommerce table woocommerce_downloadable_product_permissions was not created. We knew we had to change the database prefix to something else. Definitely something much less than 20 characters.
Changing the Database Prefix
Important: Database prefix should not be changed by directly editing wp-config.php. Doing so, may break the site.
The article, on changing database prefix, explains a reliable way to change the database prefix manually, in the section ‘Changing default table prefix after Installing WordPress’. Alternatively, you could use a plugin, like Change DB Prefix to achieve the same results.
After changing the database prefix, deactivate the WooCommerce plugin and activate it again, to ensure that the tables are created. This solved our issue, and should solve your problems too. Do you have a better method to solve this issue or is your problem still not solved? If yes, feel free to let us all know about it by commenting below.