Want more features on Pastebin? Sign Up, it's FREE!
Guest

Update Post meta...please?

By: a guest on Dec 4th, 2012  |  syntax: PHP  |  size: 1.78 KB  |  views: 54  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. First Product, with pre-existing metadata in _cp_array:
  2.  
  3. Product ID: 421
  4. No SKU Change
  5. No Price Change.
  6. Table Rate Prices Updated.
  7. array ( 'state' => '1', 'quantity' => array ( 0 => '11', 1 => '100', 2 => '250', ), 'table_price' => array ( 0 => '15.75', 1 => '14.94', 2 => '14.15', ), )
  8. '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";}}'
  9.  
  10. Note the last value for table_price - 14.15
  11.  
  12. After running function, the data in the DB for that product's _cp_array:
  13. 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";}}
  14.  
  15. Note the last value for table_price - 14.16.
  16.  
  17. Second product, without pre-existing metadata in _cp_array:
  18. Product ID: 412
  19. No SKU Change
  20. No Price Change.
  21. Table Rate Prices Updated.
  22. array ( 'state' => '1', 'quantity' => array ( 0 => '11', 1 => '100', 2 => '250', ), 'table_price' => array ( 0 => '7.80', 1 => '7.35', 2 => '6.85', ), )
  23. '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";}}'
  24.  
  25. After running function, the data in the DB for that product's _cp_array:
  26. 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";}}
  27.  
  28. 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.
  29.  
  30. The below code is responsible for updating the product's _cp_array:
  31. if(update_post_meta($id, '_cp_array', $unserialized))
  32.   echo 'Table Rate Prices Updated.<br />';
  33. else echo 'No Table Rate Change.';
clone this paste RAW Paste Data