title: Add editable address fields to WooCommerce invoice page
body: <p>Please forgive such a basic question. I'm relatively new to WooCommerce theme development and genuinely trying to understand how wordpress handles customer data so I can learn how to manipulate it. If this question is still too broad, (My previous question was closed for that reason) I'd even welcome a few links which help point me in the correct direction and explain the area I'm looking at.</p>
  
  <p>What I am trying to do is add editable address fields to the page customers see when we email them an invoice. (form-pay.php)</p>
  
  <p>Initially, I tried adding fields manually using variation on the following code for each field in functions.php and calling it in from order-pay.php:</p>
  
  <pre><code>&lt;p class="form-row form-row-first"&gt;
  &lt;label for="billing_first_name"&gt;&lt;?php _e( 'First name', 'woocommerce' ); ?&gt;&lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt;
  &lt;input type="text" class="input-text" name="billing_first_name" id="billing_first_name" value="&lt;?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?&gt;" /&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>However, when I do it this way, it adds the address details associated with my own WordPress login, rather than the customer's address associated with the invoice.</p>
  
  <p>I have worked through the <a href="https://docs.woocommerce.com/document/introduction-to-hooks-actions-and-filters/" rel="nofollow noreferrer">woocommerce codex</a> on hooks and filters  and also found the answer to <a href="https://stackoverflow.com/questions/49882391/display-billing-and-shipping-fields-in-pay-to-order-page-woocommerce">this</a> question which allowed the correct address fields to be added.  </p>
  
  <p>This is where my question seems to differ from a lot of the solutions I've found, in that most solutions are for updating the billing and shipping address of the current cart or logged in user, rather than that associated with a specific invoice.</p>
  
  <p>Here's the fields I've added to form-pay.php. </p>
  
  <pre><code>&lt;h2 class="woocommerce-column__title"&gt;&lt;?php esc_html_e( 'Billing address', 'woocommerce' ); ?&gt;&lt;/h2&gt;
  &lt;address&gt;
      &lt;?php echo wp_kses_post( $order-&gt;get_formatted_billing_address( __( 'N/A', 'woocommerce' ) ) ); ?&gt;
      &lt;?php if ( $order-&gt;get_billing_phone() ) : ?&gt;
          &lt;p class="woocommerce-customer-details--phone"&gt;&lt;?php echo esc_html( $order-&gt;get_billing_phone() ); ?&gt;&lt;/p&gt;
      &lt;?php endif; ?&gt;
      &lt;?php if ( $order-&gt;get_billing_email() ) : ?&gt;
          &lt;p class="woocommerce-customer-details--email"&gt;&lt;?php echo esc_html( $order-&gt;get_billing_email() ); ?&gt;&lt;/p&gt;
      &lt;?php endif; ?&gt;
  &lt;/address&gt;
  
  &lt;h2 class="woocommerce-column__title"&gt;&lt;?php esc_html_e( 'Shipping address', 'woocommerce' ); ?&gt;&lt;/h2&gt;
  &lt;address&gt;
      &lt;?php echo wp_kses_post( $order-&gt;get_formatted_shipping_address( __( 'N/A', 'woocommerce' ) ) ); ?&gt;
  &lt;/address&gt;
  
  &lt;!-- Form --&gt;
  &lt;h3&gt;&lt;?php _e( 'Billing details', 'woocommerce' ); ?&gt;&lt;/h3&gt;
  &lt;?php do_action( 'woocommerce_before_checkout_billing_form', $order ); ?&gt;
  &lt;div class="woocommerce-billing-fields__field-wrapper"&gt;
      &lt;?php
      $fields = WC()-&gt;checkout-&gt;get_checkout_fields( 'billing' );
      foreach ( $fields as $key =&gt; $field ) {
          $field_name = $key;
  
          if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
              $field['value'] = $order-&gt;{"get_$field_name"}( 'edit' );
          } else {
              $field['value'] = $order-&gt;get_meta( '_' . $field_name );
          }   
          woocommerce_form_field( $key, $field, $field['value'] );
      }
      ?&gt;
  &lt;/div&gt;
  &lt;?php do_action( 'woocommerce_after_checkout_billing_form', $order ); ?&gt;
  
  &lt;h3&gt;&lt;?php _e( 'Shipping details', 'woocommerce' ); ?&gt;&lt;/h3&gt;
  &lt;?php do_action( 'woocommerce_before_checkout_shipping_form', $order ); ?&gt;
  &lt;div class="woocommerce-shipping-fields__field-wrapper"&gt;
      &lt;?php
      $fields = WC()-&gt;checkout-&gt;get_checkout_fields( 'shipping' );
      foreach ( $fields as $key =&gt; $field ) {
          $field_name = $key;
  
          if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
              $field['value'] = $order-&gt;{"get_$field_name"}( 'edit' );
          } else {
              $field['value'] = $order-&gt;get_meta( '_' . $field_name );
          }   
          woocommerce_form_field( $key, $field, $field['value'] );
      }
      ?&gt;
  &lt;/div&gt;
  &lt;?php do_action( 'woocommerce_after_checkout_shipping_form', $order ); ?&gt;
  </code></pre>
  
  <p>The fields correctly appear on the invoice page now which display all address details I have already added to the invoice. I just need to understand what logic I need to attach to a button to tell WooCommerce to update the record.</p>
  
  <p>As I said, I recognise this is a fundamentally basic question, but so far I've failed to find an explanation that works specifically in the context of updating the invoice rather than the cart.</p>