Serialized license key data can be corrupted when migrating to a new domain and updating its references in the database.
When serialized data is corrupted, the license key information will remain in the database but WordPress will fail to unserialize it, returning a false
value instead. This will provoke license keys to be un-obtainable by the system.
How to detect if a License Key data is corrupted?
License key data is stored inside the WooCommerce order item meta table (woocommerce_order_itemmeta
) under the meta key _license_key
. Use the following query to retrieve and analyze the license key data:
SELECT * FROM {wp prefix}woocommerce_order_itemmeta WHERE meta_key = '_license_key' LIMIT 50;
The serialized data will be returned under the column meta_value
, and will look something similar to this:
a:7:{s:4:"code";s:26:"28d3Sy30rY0bux476A4O68GZ5k";s:6:"expire";i:1550970168;s:4:"uses";a:0:{}s:5:"limit";a:1:{s:5:"count";i:1;}s:7:"offline";N;s:12:"downloadable";a:2:{s:4:"name";s:6:"v1.5.5";s:3:"url";s:97:"http://mynewdomain.com/releases/mysoftware-1.5.5.zip";}s:6:"ctoken";s:13:"5df6a066e63a3";}
The type of data that will most likely become corrupted is strings, which are identified by as s:[number]
(the number indicates the number of characters contained in the string value).
Taking a close look at the sample above, notice that the string value s:97:"http://mynewdomain.com/releases/mysoftware-1.5.5.zip"
does not match the length indicated by the serialization; the serialization indicates a length of 97
but the actual value has a length of 52
, thus making the data corrupted. (Click here to visit a character count tool)
How to fix a corrupted License Key data?
Corrupted data needs to be fixed manually in the database. There are two options:
- Update 1 by 1 each license key.
- Update multiple license keys with an SQL script.
To update multiple data, first, verify what do you want to replace with the following script sample:
SELECT REPLACE( meta_value, 's:97:"http://mynewdomain.com/releases/mysoftware-1.5.5.zip"', 's:52:"http://mynewdomain.com/releases/mysoftware-1.5.5.zip"' ) as replacement, meta_value AS original FROM {wp prefix}woocommerce_order_itemmeta WHERE meta_key = '_license_key' AND meta_value LIKE '%s:97:"http://mynewdomain.com/releases/mysoftware-1.5.5.zip"%';
Then utilize the following SQL script as a base to update multiple corrupted license keys:
UPDATE {wp prefix}woocommerce_order_itemmeta SET meta_value = REPLACE( meta_value, 's:97:"http://mynewdomain.com/releases/mysoftware-1.5.5.zip"', 's:52:"http://mynewdomain.com/releases/mysoftware-1.5.5.zip"' ) WHERE meta_key = '_license_key' AND meta_value LIKE '%s:97:"http://mynewdomain.com/releases/mysoftware-1.5.5.zip"%';
If using the extension plugin; run the option “Bake & Sync” once all corrupted data has been fixed to update the index table.