Support

Account

Home Forums Add-ons Repeater Field Sum Repeater fields Reply To: Sum Repeater fields

  • If you want to get the total of each product you could use an array, but I’m not sure how you’d use for your output.

    
    $total_items = array();
    if (have_rows('shipment')) {
      while (have_rows('shipment')) {
        $product_name = get_field('product_name;);
        // initialize count for this product
        if (!isset($total_items[$product_name])) {
          $total_items[$product_name] = 0;
        }
        $total_items[$product_name] += get_sub_field('product_quantity');
      }
    }
    echo '<pre>'; print_r($total_items); echo '</pre>';