First Product, with pre-existing metadata in _cp_array:
Product ID: 421
No SKU Change
No Price Change.
Table Rate Prices Updated.
array ( 'state' => '1', 'quantity' => array ( 0 => '11', 1 => '100', 2 => '250', ), 'table_price' => array ( 0 => '15.75', 1 => '14.94', 2 => '14.15', ), )
'a:3:{s:5:"state";s:1:"1";s:8:"quantity";a:3:{i:0;s:2:"11";i:1;s:3:"100";i:2;s:3:"250";}s:11:"table_price";a:3:{i:0;s:5:"15.75";i:1;s:5:"14.94";i:2;s:5:"14.15";}}'
Note the last value for table_price - 14.15
After running function, the data in the DB for that product's _cp_array:
a:3:{s:5:"state";s:1:"1";s:8:"quantity";a:3:{i:0;s:2:"11";i:1;s:3:"100";i:2;s:3:"250";}s:11:"table_price";a:3:{i:0;s:5:"15.75";i:1;s:5:"14.94";i:2;s:5:"14.16";}}
Note the last value for table_price - 14.16.
Second product, without pre-existing metadata in _cp_array:
Product ID: 412
No SKU Change
No Price Change.
Table Rate Prices Updated.
array ( 'state' => '1', 'quantity' => array ( 0 => '11', 1 => '100', 2 => '250', ), 'table_price' => array ( 0 => '7.80', 1 => '7.35', 2 => '6.85', ), )
'a:3:{s:5:"state";s:1:"1";s:8:"quantity";a:3:{i:0;s:2:"11";i:1;s:3:"100";i:2;s:3:"250";}s:11:"table_price";a:3:{i:0;s:4:"7.80";i:1;s:4:"7.35";i:2;s:4:"6.85";}}'
After running function, the data in the DB for that product's _cp_array:
a:3:{s:5:"state";s:1:"1";s:8:"quantity";a:2:{i:0;s:2:"11";i:1;s:2:"12";}s:11:"table_price";a:2:{i:0;s:4:"3.00";i:1;s:4:"2.00";}}
Both of the above functions have been run multiple times, with the same result every time, even though the array '$unserialized' stays the same every time.
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.';