My plugin is a custom export/update plugin that lets the user export his products, update the price grids, and upload the csv to change the data quicker than using the visual editor.
The price grids are stored as a serialized array in the post's meta (_cp_array).
To test my plugin, I uploaded a csv with data identical to that which was already in the DB. The function below informed that the Table Rates had not changed (because they hadn't!).
Next, I changed ONE value in ONE row of the csv. Tested again. This time, the function informed that for the product I changed, the post meta had been updated.
However, the meta is never actually updated. Looking in the DB for the meta (_cp_array), the serialized string stays the same after running my upload function multiple times, with update_post_meta returning true each time, and echoing the "updated" message.
For debugging purposes, I used var_export($unserialized) to see what it outputted, and also var_export(serialize($unserialized)) to see what the data should look like when writing the serialized array/string to the DB.
The var_export (serialized and not) on my plugin screen always displays the new, changed data from the csv.
It gets even stranger...next I tried adding new metadata to a product that didn't have anything for that specific metadata (it was empty and the meta key didn't exist for that product). The function displays that it updated the metadata for that product. However, looking in the DB reveals that the serialized value for that product's meta (_cp_array) was very different from the data I entered! The var_export displays the correct array and serialized string, but the DB had very different keys and values!
All relevant examples/info: http://pastebin.com/Wa3deaUy
Why is the plugin not changing the metadata, even though the function returns true? And why, when it added new metadata, did it add incorrect metadata, even though the serialized array was correct when outputted to the screen?
The below code is responsible for updating the product's _cp_array:
if(update_post_meta($id, '_cp_array', $unserialized)) echo 'Table Rate Prices Updated.<br />'; else echo 'No Table Rate Change.'; var_export($unserialized); echo '<br />'; var_export(serialize($unserialized));