@jonathan It’s for the Swedish posten.se ( inte så hightech ) , to prefill tracking numbers like this https://posten.se/tracktrace/TrackConsignments_do.jsp?&consignmentId=916355578312&consignmentId=916355573216&consignmentId=91635557310&consignmentId=91635547833&consignmentId=916332157847&consignmentId=916331257855&consignmentId=
Thanks for the feedback, PHP is one of my weakest languages so it tend to be a bit messy, will update my code with the things you suggested.
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;
}
So the final solution for my project was a function looking like this
function trackingNo($postID) {
$field_rep = 'trackingNo';
$field_sub = 'no';
if (have_rows($field_rep, $postID)) {
$trackingNo = array();
// loop through the rows of data
while (have_rows($field_rep, $postID)):
the_row();
// Add to array
$trackingNo[] = get_sub_field($field_sub);
endwhile;
$foo = implode('&consignmentId=', $trackingNo);
$bar = 'http://url.com/tracktrace/TrackConsignments_do.jsp?&consignmentId=';
$value = $bar . $foo;
return $value;
}
}
If there is any room for improvement in the function please let me know. am pretty weak in PHP.
@jonathan The feeling you get when spending 10 hours trying to solve something just to realize that you all the time used ‘trackingno’ instead of the correct ‘trackingNo’
FML! 😀 , But alright now i got somewhere with this, will post my final code for this once am done.
@elliot Thanks, I had this option in mind but wanna check with you first if there was any other option to it.
Thanks !
Keep up the great work, you are creating something really good that more and more people will keep discover!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.