6

I am struggling with using additional custom order fields. (Added in the Craft Commerce settings at "order fields", in the field layout manager)

I try to update them like this in the checkout process:

<form method="POST">
    <input type="hidden" name="action" value="commerce/cart/updateCart">
    <input type="text" name="myCustomField" value="Test123">
    ...
    <input type="submit" value="Update Custom Field">
</form>

But in the Order in the CP, the field stays empty. Do I have to use another name for the field, like fields[myCustomField] or whatever?

I can update them in the CP, but not from the front-end...

1 Answer 1

12

Correct, you need to use fields[customFieldName] as the input name.

The following form should do it:

<form method="POST">
    <input type="hidden" name="action" value="commerce/cart/updateCart">
    <input type="text" name="fields[myCustomField]" value="Test123">
    ...
    <input type="submit" value="Update Custom Field">
</form>
2
  • Sweet! Is there also a way to validate those fields?
    – exophunk
    Commented Jan 6, 2016 at 8:24
  • Validation would need to be front end only for now. Commented Sep 18, 2016 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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