I managed to solve it and am posting for future readers. The issue was that I was focusing on the wrong variable. I was trying to loop through the subfield value but it was already being looped and calculated to a different variable.
<?php if( have_rows('packaging_sessions') ): ?> <table> <caption>Packaging Sessions </caption> <thead> <tr> <th>Quantity × Capacity </th> <th>Volume </th> </tr> </thead> <tbody> <?php $total_finished_packages = 0; while( have_rows('packaging_sessions') ): the_row(); // vars $packaging_capacity = get_sub_field('packaging_capacity'); // The select subfield in the repeater (size) $package_capacity_value = esc_attr($packaging_capacity['value']); // The select field's values $package_capacity_label = esc_html($packaging_capacity['label']); // The select field's labels $packaging_quantity = get_sub_field('packaging_quantity'); // The quantity of packaged units $finished_package = $packaging_quantity * ($package_capacity_value * .001); // The quantity x size ?> <tr> <td><!-- Quantity & Capacity --> <?php echo (int)$packaging_quantity . " × " . $package_capacity_label ?> </td> <td><!-- Volume --> <?php echo $finished_package; ?> </td> </tr> <?php // Iterate through the capacities and quantities $total_finished_packages += $packaging_capacity * $packaging_quantity ; ?> <?php endwhile; ?> </tbody> </table> <!-- Sum volume of all package combinations --> <?php echo 'Total packaged volume is ' . $total_finished_packages ; ?>
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!