Support

Account

Forum Replies Created

  • 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 ; ?>
  • Brilliant, John. Thank you for pointing me in the right direction!

Viewing 2 posts - 1 through 2 (of 2 total)