Skip to main content

Localized Fields

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.

<[]>

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.

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

[]

[]

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

required

| undefined
Examples

Preact

import '@shopify/ui-extensions/preact';
import {render} from 'preact';

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

export default function extension() {
render(<Extension />, document.body);
}

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

// 2. 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',
};
},
);
}
Was this page helpful?