Skip to main content

Localized Fields
API

Requires access to protected customer data for some properties.

The API for interacting with localized fields.

The base API object provided to purchase extension targets.

StatefulRemoteSubscribable<[]>

The API for reading additional fields that are required in checkout under certain circumstances. For example, some countries require additional fields for customs information or tax identification numbers.

Was this section helpful?

Returns the current localized fields and re-renders your component if the values change.

[]

[]
Was this section helpful?

Returns the requested localized field and re-renders your component if the value changes.

required

| undefined
Was this section helpful?

Read localized fields

import {
reactExtension,
useBuyerJourneyIntercept,
useLocalizedField,
} from '@shopify/ui-extensions-react/checkout';

// 1. Choose an extension target
export default reactExtension(
'purchase.checkout.block.render',
() => <Extension />,
);

function Extension() {
// 2. Access localized field value
const taxIdField = useLocalizedField(
'TAX_CREDENTIAL_BR',
);

// 3. Validate localized field value
useBuyerJourneyIntercept(
({canBlockProgress}) => {
return canBlockProgress &&
taxIdField &&
(!taxIdField.value ||
taxIdField.value.length > 10)
? {
behavior: 'block',
reason: 'Invalid tax ID',
errors: [
{
message: `${taxIdField.title} is required and
cannot exceed 10 characters in length`,
// Show an error under the field
target: `$.cart.localizedField.${taxIdField.key}`,
},
],
}
: {
behavior: 'allow',
};
},
);
}