Now am about to go crazy over this.
How do i save values put in like this
$field_rep = 'trackingNo';
$field_sub = 'no';
$field_key_rep = 'field_55f10e0fd8b5f';
$field_key_sub = 'field_55f10e3dd8b60';
foreach ($misc->PackageNo as $package) {
$trackno = (string)$package->TrackingNo;
update_post_meta("$order_id", $field_rep, $count);
$sub = $count;
update_sub_field(array($field_key_rep, $sub, $field_key_sub), $trackno, "$order_id");
$count = $count + 1;
}
The values are there but it’s not possible to retrieve and use them until the post/order (woocommerce) is updated by hand.
So to keep it short, creating new rows and adding my information works fine but to use it before doing a update on it will not work.
Finally manage to solve it
Putting the data there was more or less correct like
update_post_meta( "$order_id", $field_rep, $row_no );
update_sub_field(array($field_key_rep, $sub_no, $field_key_sub), $trackno, "$order_id");
Think the main problem was when fetching the information and then doing it with the field names that would not work until the post was updated / saved. Using field_keys did on the other hand work.
if (have_rows($field_key_rep, $postID)) {
$trackingNo = array();
// loop through the rows of data
while (have_rows($field_key_rep, $postID)):
the_row();
// Add to array
$trackingNo[] = get_sub_field($field_key_sub);
endwhile;
}
I was just looking into something similar on another topic. Instead of update_sub_field() which only lets you update existing sub fields, use update_field() and pass it an array of values for the sub_fields. There is an example of adding sub fields under “Usage”