3

I would like to add a set of additional fields to the order summary so after a user adds a product they would need to fill out some conditional fields of information alongside their billing information.

Drupal Commerce 2 documentation is pretty lacking at the moment and I am expecting to change the YAML files to add new fields. However, there seem to be various places to add new fields but nothing is showing up as additional fields on the order summary page.

What are the steps to add new fields?

4
  • Not sure why it was edited to remove Drupal 8 and Commerce 2, without those, it's not clear what I am asking.
    – BigEd
    Jun 28 '17 at 12:46
  • On a site about Drupal, it is rather useless to include Drupal in the title. For that reason it is often edited out. But I agree with you that commerce 2 should have remained in. Jun 28 '17 at 16:56
  • Are these product specific fields, like a custom text to engrave on a certain product, or are these global order fields? Jun 28 '17 at 16:58
  • Thanks for reposting. Yes these are custom fields that do not need to be on the product its self, but we need to collect more information about the user, ideally, these would be text fields for the user to fill out and possible field collections. The order summary seems like an ideal place to add these, however, I could create a new custom pane to add to the checkout process to contain these fields.
    – BigEd
    Jun 29 '17 at 10:19
3

I found the answer to this, it's not very obvious at the moment due to the lack of documentation but it's blinding simple when you know how.

Install the new profile module. https://www.drupal.org/project/profile

Edit the page:

configuration > people > user profile

Here you can add commerce2 user pane or new fields.

For me I needed to make a new Content type form that the user could create and fill out as part of the checkout process, so I used the inline entity form.

Really you could use any field collections or paragraph's to add to the user fields as I notice there is a new patch to support field group and paragrahs.

I hope that helps someone else looking for this answer.

1

Since the release of Commerce 2, there are some new recent changes that add an additional way to add fields to an order. Which maybe better than the previous way.

To add a new field to the order:

  1. Add your field on /admin/commerce/config/order-types/default/edit/fields
  2. On the Manage form display add the new CUSTOM DISPLAY SETTINGS checkbox Checkout
  3. On your new display for checkout add only your field.
  4. Then navigate to the Oder Checkout flows, we are using default. /admin/commerce/config/checkout-flows add the Order fields: Checkout to the Order Information section. You can add a fieldset at this point in the options.
  5. Save and view the field.

For this to display in the commerce-order-receipt.html.twig you will need to add a twig changing the field name for your machine name.

  {% if order_entity.field_name.value %}
    {{ order_entity.field_name.value }}
  {% endif %}

Then finally. To have the custom fields on order admin view page you will need to add this patch.

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.