8 – Save customer information at checkout


Not sure this would be the recommended way but I got it working using hook_form_alter. Customers start by filling their shipping address at step 1 (required) and on complete step, I grab this shipping address and copy it to the customer_information address field on guest registration, so the customers don’t need to fill the same address again. In case the customer address would be different, it can be modified at this step.

/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Commerce checkout form
  if ($form_id === 'commerce_checkout_flow_multistep_default') {

    // Multistep "complete" step
    if ($form('#step_id') === 'complete') {

      // Get shipping address and copy it to customer profile address
      $profiles = $form_state->getFormObject()->getOrder()->collectProfiles();
      $shipping_address = $profiles('shipping')->address->getValue();
      $form('completion_register')('customer_profiles')('widget')(0)('entity')('address')('widget')(0)('address')('#default_value') = reset($shipping_address);
    }
  }
}