Skip to main content

useBuyerJourneyIntercept

Installs a function for intercepting and preventing progress on checkout.

To block checkout progress, you must set the block_progress capability in your extension's configuration.

If you do, then you're expected to inform the buyer why navigation was blocked, either by passing validation errors to the checkout UI or rendering the errors in your extension.

Anchor to interceptor
interceptor
required

Anchor to interceptorrequestblockInterceptorRequestBlock

Block the buyer from proceeding further in the checkout

Anchor to behavior
behavior
"block"
required

Indicates that the interceptor will block the buyer's journey from continuing.

Anchor to reason
reason
string
required

The reason for blocking the interceptor request. This value isn't presented to the buyer, so it doesn't need to be localized. The value is used only for Shopify’s own internal debugging and metrics.

Anchor to errors
errors
[]

Used to pass errors to the checkout UI, outside your extension's UI boundaries.

Anchor to perform
perform
(result: ) => void | Promise<void>

This callback is called when all interceptors finish. We recommend setting errors or reasons for blocking at this stage, so that all the errors in the UI show up at once.

Anchor to interceptorrequestallowInterceptorRequestAllow

Allow the buyer to proceed further in the checkout

Anchor to behavior
behavior
"allow"
required

Indicates that the interceptor will allow the buyer's journey to continue.

Anchor to perform
perform
(result: ) => void | Promise<void>

This callback is called when all interceptors finish. We recommend setting errors or reasons for blocking at this stage, so that all the errors in the UI show up at once.

Examples

React

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

export default reactExtension(
'purchase.checkout.delivery-address.render-before',
() => <Extension />,
);

function Extension() {
const address = useShippingAddress();

useBuyerJourneyIntercept(
({canBlockProgress}) => {
return canBlockProgress &&
address?.countryCode &&
address.countryCode !== 'CA'
? {
behavior: 'block',
reason: 'Invalid shipping country',
errors: [
{
message:
'Sorry, we can only ship to Canada',
// Show an error underneath the country code field
target:
'$.cart.deliveryGroups[0].deliveryAddress.countryCode',
},
{
// In addition, show an error at the page level
message:
'Please use a different address.',
},
],
}
: {
behavior: 'allow',
};
},
);

return null;
}
Was this page helpful?