-
Notifications
You must be signed in to change notification settings - Fork 211
ECE: Add support for custom fields in block checkout #4390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
583132b
to
c97c74f
Compare
Sample code snippet to add custom fields via the Additional Checkout Fields API:
|
2bbe0dd
to
4dfbba7
Compare
4dfbba7
to
f82e492
Compare
f82e492
to
93ccf89
Compare
📈 PHP Unit Code Coverage Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for passing custom checkout fields (registered via the Additional Checkout Fields API) through express payment methods in block checkout.
- Exposes custom field configuration from PHP to JS for express checkout.
- Enhances
normalizeOrderData
and related utilities to include custom billing, shipping, and additional fields. - Updates front-end error formatting and the API call to accept the full order payload.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
readme.txt | Added changelog entry for block checkout custom fields support |
includes/payment-methods/class-wc-stripe-express-checkout-element.php | Added get_custom_checkout_fields() to localize custom field IDs |
client/express-checkout/utils/normalize.js | Extended normalizer to merge custom billing/shipping/additional fields |
client/express-checkout/utils/index.js | Improved safety and early-return in error‐message parsing |
client/express-checkout/utils/tests/normalize.test.js | Added tests covering additional fields and custom address fields |
client/express-checkout/payment-flow.js | Added REST parameter error concatenation and formatting |
client/blocks/express-checkout/hooks.js | Render multiline messages with <br> before setting error state |
client/api/index.js | Renamed and streamlined expressCheckoutECECreateOrder() to send full order data |
changelog.txt | Updated changelog entry |
Comments suppressed due to low confidence (2)
includes/payment-methods/class-wc-stripe-express-checkout-element.php:235
- The docblock says "field IDs" but the method returns an associative array of configs (
key
andlocation
). Please update the @return description to reflect the actual structure.
* @return array Custom checkout field IDs.
client/express-checkout/utils/tests/normalize.test.js:137
- There aren't tests for the non-block-checkout path of
getAdditionalFieldsData
or the custom-address helpers. Adding a test whereisBlockCheckoutPage()
is false would ensure stale data isn't sent.
describe( 'normalizeOrderData', () => {
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
@@ -3,7 +3,12 @@ import { getErrorMessageFromNotice, normalizeOrderData } from './utils'; | |||
|
|||
const handlePaymentFlowException = ( event, exception, abortPayment ) => { | |||
let errorMessage; | |||
if ( exception.message ) { | |||
|
|||
if ( exception.code === 'rest_invalid_param' && exception.data?.params ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: I would move this to a constant.
postcode: shipping?.address?.postal_code ?? '', | ||
method: [ event?.shippingRate?.id ?? null ], | ||
}, | ||
billing_address: getBillingAddressData( event ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor!
|
||
const data = { | ||
first_name: | ||
shipping?.name?.split( ' ' )?.slice( 0, 1 )?.join( ' ' ) ?? '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Maybe we could have a helper method for the names, since both share the same logic
|
||
const customerData = getCustomerDataFromStore(); | ||
|
||
if ( ! customerData || ! customerData.shippingAddress ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ( ! customerData || ! customerData.shippingAddress ) { | |
if ( ! customerData?.shippingAddress ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is good and works as expected! Left some optional comments.
- Verify in the Order Confirmation page that the fields have been persisted.

- Try using ECE in the product or cart pages.
Verify there are no unexpected failures. See known limitations about required custom fields below.

Verify it avoids using stale session data: since the custom fields are not presented to the shopper inside these pages, there should be no custom data stored for these orders.

Partially fixes STRIPE-205
Partially fixes #2969
Changes proposed in this Pull Request:
This PR adds support for ECE and custom checkout fields, limited to:
woocommerce_register_additional_checkout_field()
).In subsequent PRs, we will add support for
extensions
(block checkout only) (ECE: add support for extensions data #4394)Testing instructions
wp_wc_orders_meta
.meta_key
will be prefixed with_wc_billing/
,_wc_shipping/
or_wc_other/
.Known limitations:
woocommerce_register_additional_checkout_field()
, express checkout will fail when the data is not provided. This invariably means ECE is not usable outside of the block checkout page.Changelog entry
Changelog Entry Comment
Comment
Post merge