Home › Forums › Add-ons › Repeater Field › Woocommerce Order: get_sub_field array › Reply To: Woocommerce Order: get_sub_field array
Hi,
If it works!
What throws me off a bit is that you’re “glueing” together all of your trackinNos with “&consignmentId=” which if you have multiple numbers should result in something like:
etc.
To me that kind of URL makes no sense as you’d have multiple values for the same GET parameter in the URL.
Otherwise I think your code looks good. I prefer to not use variables for strings if not needed (or if the code is very long and it’s easier because changing would require a change to many places. I would also suggest to use more descriptive variablenames than foo and bar which are used for generic examples.
<?php
function trackingNo($postID) {
if ( have_rows('trackingNo', $postID) ) {
$trackingNo = array();
// loop through the rows of data
while ( have_rows('trackingNo', $postID) ): the_row();
// Add to array
$trackingNo[] = get_sub_field('no');
endwhile;
$trackingNoString = implode('&consignmentId=', $trackingNo);
$base = 'http://url.com/tracktrace/TrackConsignments_do.jsp?&consignmentId=';
$value = $base . $trackingNoString;
return $value;
}
}
?>
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.