I am writing a custom CheckoutPaneBase within Commerce 2 that incorporates shipping and billing information. My goal would be to update the customer's billing address, that is stored as billing profile, programmatically. I looked at the billing information Pane and see that they use:

  $billing_profile = $this->order->getBillingProfile();
      if (!$billing_profile) {
        $billing_profile = $this->entityTypeManager->getStorage('profile')->create([
          'type' => 'customer',
          'uid' => 0,
      $billing_profile->populateFromProfile($payment_method_profile, ['data']);

But rather that populate from $payment_method_profile, I would like to add my own fields' values. I am not sure how I can populate an array to push to populateFromProfile or setBillingProfile or the field values.

Any help or hints?


You can update the field value like this:

  $cart_provider = \Drupal::service('commerce_cart.cart_provider');
  $cart = $cart_provider->getCart('default');
  $billing_profile = $cart->getBillingProfile();
  $billing_profile->field_name->value = 'Hello World';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.