title: How to update the clone fields which is inside the repeater field in ACF?
body: <p>I have a field group named 'Sales Item' and 'Invoice'. The invoice field group have a 'Items' field which is a repeater field, the 'Items' field contains the 'Sales Item' field group as clone field.</p>
  
  <p>I need to create an Invoice post type programmatically. All the field of the 'Invoice' is created except the 'Items' field. How do I add the data to the 'Items' reaper field which contain the 'Sales Item' clone field?</p>
  
  <p><strong>Sales Item and Invoice field group.</strong></p>
  
  <pre><code>[
      {
          "key": "group_5c4033565a799",
          "title": "Invoice",
          "fields": [
              {
                  "key": "field_5c44150d123de",
                  "label": "Type",
                  "name": "ims_invoice_type",
                  "type": "select",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "choices": {
                      "sales": "Sales",
                      "purchases": "Purchases"
                  },
                  "default_value": [
                      "purchases"
                  ],
                  "allow_null": 0,
                  "multiple": 0,
                  "ui": 0,
                  "return_format": "value",
                  "ajax": 0,
                  "placeholder": ""
              },
              {
                  "key": "field_5c4033c40bce3",
                  "label": "Invoice Number",
                  "name": "ims_invoice_invoice_number",
                  "type": "text",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "default_value": "",
                  "maxlength": "",
                  "placeholder": "",
                  "prepend": "",
                  "append": ""
              },
              {
                  "key": "field_5c4e943170485",
                  "label": "Customer",
                  "name": "ims_invoice_customer",
                  "type": "relationship",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": [
                      [
                          {
                              "field": "field_5c44150d123de",
                              "operator": "==",
                              "value": "sales"
                          }
                      ]
                  ],
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "post_type": [
                      "ims_customer"
                  ],
                  "taxonomy": "",
                  "filters": [
                      "search",
                      "post_type",
                      "taxonomy"
                  ],
                  "elements": "",
                  "min": 1,
                  "max": 1,
                  "return_format": "object"
              },
              {
                  "key": "field_5c4033620bce1",
                  "label": "Vendor",
                  "name": "ims_invoice_vendor",
                  "type": "relationship",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": [
                      [
                          {
                              "field": "field_5c44150d123de",
                              "operator": "==",
                              "value": "purchases"
                          }
                      ]
                  ],
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "post_type": [
                      "ims_vendor"
                  ],
                  "taxonomy": "",
                  "filters": [
                      "search",
                      "post_type",
                      "taxonomy"
                  ],
                  "elements": "",
                  "min": 1,
                  "max": 1,
                  "return_format": "object"
              },
              {
                  "key": "field_5c40339b0bce2",
                  "label": "Date",
                  "name": "ims_invoice_date",
                  "type": "date_picker",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "display_format": "F j, Y",
                  "return_format": "d\/m\/Y",
                  "first_day": 0
              },
              {
                  "key": "field_5c4034030cff9",
                  "label": "Items",
                  "name": "ims_invoice_sales_items",
                  "type": "repeater",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": [
                      [
                          {
                              "field": "field_5c44150d123de",
                              "operator": "==",
                              "value": "sales"
                          }
                      ]
                  ],
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "collapsed": "",
                  "min": 0,
                  "max": 0,
                  "layout": "table",
                  "button_label": "Add Product",
                  "sub_fields": [
                      {
                          "key": "field_5c443f4dd87de",
                          "label": "Item",
                          "name": "ims_invoice_sales_items",
                          "type": "clone",
                          "instructions": "",
                          "required": 0,
                          "conditional_logic": 0,
                          "wrapper": {
                              "width": "",
                              "class": "",
                              "id": ""
                          },
                          "clone": [
                              "group_5c443e86ad330"
                          ],
                          "display": "seamless",
                          "layout": "block",
                          "prefix_label": 0,
                          "prefix_name": 1
                      }
                  ]
              },
              {
                  "key": "field_5c78f715c5efe",
                  "label": "Items",
                  "name": "ims_invoice_purchases_items",
                  "type": "repeater",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": [
                      [
                          {
                              "field": "field_5c44150d123de",
                              "operator": "==",
                              "value": "purchases"
                          }
                      ]
                  ],
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "collapsed": "",
                  "min": 0,
                  "max": 0,
                  "layout": "table",
                  "button_label": "Add Product",
                  "sub_fields": [
                      {
                          "key": "field_5c78f730c5eff",
                          "label": "Items",
                          "name": "ims_invoice_purchases_items",
                          "type": "clone",
                          "instructions": "",
                          "required": 0,
                          "conditional_logic": 0,
                          "wrapper": {
                              "width": "",
                              "class": "",
                              "id": ""
                          },
                          "clone": [
                              "group_5c78e0e32443c"
                          ],
                          "display": "seamless",
                          "layout": "block",
                          "prefix_label": 0,
                          "prefix_name": 1
                      }
                  ]
              },
              {
                  "key": "field_5c41b2ff17b09",
                  "label": "Sub Total",
                  "name": "ims_invoice_sub_total",
                  "type": "read_only",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "copy_to_clipboard": 0,
                  "display_type": "text"
              },
              {
                  "key": "field_5c41b31a17b0b",
                  "label": "Discount",
                  "name": "ims_invoice_discount",
                  "type": "number",
                  "instructions": "",
                  "required": 0,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "default_value": "0.0",
                  "placeholder": "",
                  "prepend": "",
                  "append": "",
                  "min": 0,
                  "max": "",
                  "step": ""
              },
              {
                  "key": "field_5c41b32617b0c",
                  "label": "V.A.T",
                  "name": "ims_invoice_vat",
                  "type": "number",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "default_value": "0.0",
                  "placeholder": "",
                  "prepend": "",
                  "append": "",
                  "min": 0,
                  "max": "",
                  "step": ""
              },
              {
                  "key": "field_5c41b33317b0d",
                  "label": "Total",
                  "name": "ims_invoice_total",
                  "type": "read_only",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "copy_to_clipboard": 0,
                  "display_type": "text"
              },
              {
                  "key": "field_5c41b33b17b0e",
                  "label": "Paid",
                  "name": "ims_invoice_paid",
                  "type": "number",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "default_value": "0.0",
                  "placeholder": "",
                  "prepend": "",
                  "append": "",
                  "min": 0,
                  "max": "",
                  "step": ""
              },
              {
                  "key": "field_5c41b34517b0f",
                  "label": "Due",
                  "name": "ims_invoice_due",
                  "type": "read_only",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "copy_to_clipboard": 0,
                  "display_type": "text"
              }
          ],
          "location": [
              [
                  {
                      "param": "post_type",
                      "operator": "==",
                      "value": "ims_invoice"
                  }
              ]
          ],
          "menu_order": 0,
          "position": "normal",
          "style": "default",
          "label_placement": "left",
          "instruction_placement": "label",
          "hide_on_screen": "",
          "active": 1,
          "description": ""
      },
      {
          "key": "group_5c443e86ad330",
          "title": "Sales Item",
          "fields": [
              {
                  "key": "field_5c443eab22fe1",
                  "label": "Item",
                  "name": "sales_item_item",
                  "type": "post_object",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "post_type": [
                      "ims_product"
                  ],
                  "taxonomy": "",
                  "allow_null": 0,
                  "multiple": 0,
                  "return_format": "object",
                  "ui": 1
              },
              {
                  "key": "field_5c779ac395834",
                  "label": "SKU",
                  "name": "sales_item_sku",
                  "type": "read_only",
                  "instructions": "",
                  "required": 0,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "copy_to_clipboard": 0,
                  "display_type": "text"
              },
              {
                  "key": "field_5c443eba22fe2",
                  "label": "Quantity",
                  "name": "sales_item_quantity",
                  "type": "number",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "default_value": 1,
                  "placeholder": "",
                  "prepend": "",
                  "append": "",
                  "min": "",
                  "max": "",
                  "step": ""
              },
              {
                  "key": "field_5c443ec622fe3",
                  "label": "Unit Price",
                  "name": "sales_item_unit_price",
                  "type": "read_only",
                  "instructions": "",
                  "required": 1,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "copy_to_clipboard": 0,
                  "display_type": "text"
              },
              {
                  "key": "field_5c443edf22fe4",
                  "label": "Price",
                  "name": "sales_item_price",
                  "type": "read_only",
                  "instructions": "",
                  "required": 0,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "copy_to_clipboard": 0,
                  "display_type": "text"
              },
              {
                  "key": "field_5c443efd22fe5",
                  "label": "Discount",
                  "name": "sales_item_discount",
                  "type": "number",
                  "instructions": "",
                  "required": 0,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "default_value": "0.0",
                  "placeholder": "",
                  "prepend": "",
                  "append": "",
                  "min": "",
                  "max": "",
                  "step": ""
              },
              {
                  "key": "field_5c443f0a22fe6",
                  "label": "Amount",
                  "name": "sales_item_amount",
                  "type": "read_only",
                  "instructions": "",
                  "required": 0,
                  "conditional_logic": 0,
                  "wrapper": {
                      "width": "",
                      "class": "",
                      "id": ""
                  },
                  "copy_to_clipboard": 0,
                  "display_type": "text"
              }
          ],
          "location": [
              [
                  {
                      "param": "post_type",
                      "operator": "==",
                      "value": "post"
                  }
              ]
          ],
          "menu_order": 0,
          "position": "normal",
          "style": "default",
          "label_placement": "top",
          "instruction_placement": "label",
          "hide_on_screen": "",
          "active": 0,
          "description": ""
      }
  ]
  </code></pre>
  
  <p>Here is the code, I have written so far.</p>
  
  <pre><code>$invoice_key = 'ims_invoice_sales_items_';
  $customer_id = $_POST['customer_id'];
  $ims_products = $_POST['ims_product'];
  $basket_discount = $_POST['basket_discount'];
  $basket_vat = $_POST['basket_vat'];
  $paid = $_POST['paid'];
  
  $sub_total = 0.0;       
  foreach( $ims_products as $ims_product ) {
  
      $id = $ims_product['id'];
      $quantity = intval( $ims_product['quantity'] );
      $unit_price = floatval( get_field( 'ims_product_mrp', $id ) );
      $discount = floatval( $ims_product['discount'] );
      $price = $quantity * $unit_price;
      $amount = $price - ( $discount * $price ) / 100.0;
      $sub_total += $amount;
  
      $items [] = array(
          $invoice_key . 'sales_item_item'       =&gt; $id,
          $invoice_key . 'sales_item_sku'        =&gt; get_field( 'ims_product_sku', $id ),
          $invoice_key . 'sales_item_quantity'   =&gt; $quantity,
          $invoice_key . 'sales_item_unit_price' =&gt; $unit_price,
          $invoice_key . 'sales_item_price'      =&gt; $price,
          $invoice_key . 'sales_item_discount'   =&gt; $discount,
          $invoice_key . 'sales_item_amount'     =&gt; $amount               
      );
  }
  
  // var_dump( $items );
  
  // Calculate grand total after discount and vat.
  $grand_total = $sub_total - ( $basket_discount * $sub_total ) / 100.0;
  $grand_total = $grand_total + ( $basket_vat * $grand_total ) / 100.0;
  
  // Calculate due.
  $due = $grand_total - $paid;
  
  $meta_inputs = array(
      'ims_invoice_type'           =&gt; 'sales',
      'ims_invoice_invoice_number' =&gt; uniqid(),
      'ims_invoice_customer'       =&gt; $customer_id,
      'ims_invoice_date'           =&gt; current_time('d/m/Y', false ),
      'ims_invoice_sub_total'      =&gt; $sub_total,
      'ims_invoice_discount'       =&gt; $basket_discount,
      'ims_invoice_vat'            =&gt; $basket_vat,
      'ims_invoice_total'          =&gt; $grand_total,
      'ims_invoice_paid'           =&gt; $paid,
      'ims_invoice_due'            =&gt; $due
  );
  
  $invoice_args = array(
      'post_type' =&gt; 'ims_invoice',
      'post_status' =&gt; 'publish',
      'meta_input' =&gt; $meta_inputs
  );
  
  // var_dump( $invoice_args );
  
  $post_id = wp_insert_post( $invoice_args, true );
  
  var_dump( "&lt;h1&gt;Post Id = ${post_id}&lt;/h1&gt;");
  
  
  foreach( $items as $item ) {
  
      var_dump( $item );
      add_row( 'ims_invoice_sales_items', $item, $post_id );
  }
  
  die;
  </code></pre>