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:

    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.

    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');
            $trackingNoString = implode('&consignmentId=', $trackingNo);
            $base = '';
            $value = $base . $trackingNoString;
            return $value;