Support

Account

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:

    http://url.com/tracktrace/TrackConsignments_do.jsp?&consignmentId=1&consignmentId=2&consignmentId=3&consignmentId=4&consignmentId=5

    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;
    	}
    }
    ?>