i working on wordpress woocommerce , using wck plugin custom fields. creating products programatically.
i need save custom fields data array in database progrmatically. not saving correctly , not showing custom field values in backend products. using code.
$data= array( 'alternative-product-names' => $alternative_pname, 'manufacturers-part-number' => $manufature_park_number, 'currently-packaged'=> $currently_packaged, 'other-package-options' => $other_pkg_opt, 'inner-pack-qty' => $inner_pack_qty, 'inner-pack-dimensions' => $inner_pck_dimension, 'packaging-picture'=>'' ); update_post_meta( $post_id, 'productextrainfo1234', $data );
i need save data in format:
a:1:{i:0;a:15:{s:25:"alternative-product-names";s:4:"fgfg";s:25:"manufacturers-part-number";s:4:"gffg";s:18:"currently-packaged";s:4:"fgfg";s:21:"other-package-options";s:4:"fgfg";s:14:"inner-pack-qty";s:4:"fggf";s:21:"inner-pack-dimensions";s:17:"packaging-picture";s:3:"561";}}
after testing code:
first, have 7 lines of key/values in array, serialized string can't begin
a:1:{i:0;a:15:{ …
insteada:1:{i:0;a:7:{ …
.second, need embed array in empty array correct format want:
a:1:{i:0;a:7:{ … }};
.
so code have this:
$data= array( array( 'alternative-product-names' => $alternative_pname, 'manufacturers-part-number' => $manufature_park_number, 'currently-packaged' => $currently_packaged, 'other-package-options' => $other_pkg_opt, 'inner-pack-qty' => $inner_pack_qty, 'inner-pack-dimensions' => $inner_pck_dimension, 'packaging-picture' => '' ) ); update_post_meta( $product_id, 'productextrainfo1234', $data );
this way serialized data value in database:
a:1:{i:0;a:7:{s:25:"alternative-product-names";n;s:25:"manufacturers-part-number";n;s:18:"currently-packaged";n;s:21:"other-package-options";n;s:14:"inner-pack-qty";n;s:21:"inner-pack-dimensions";n;s:17:"packaging-picture";s:0:"";}}
instead of:
a:7:{s:25:"alternative-product-names";n;s:25:"manufacturers-part-number";n;s:18:"currently-packaged";n;s:21:"other-package-options";n;s:14:"inner-pack-qty";n;s:21:"inner-pack-dimensions";n;s:17:"packaging-picture";s:0:"";}
Comments
Post a Comment