For checkout ui extensions, is it possible to add a textfield as a metafield/attribute on the checkout before the order is submitted, rather than sending an API request to modify the order info?
Here is my current component:
import React, { useState } from 'react';
import {
useExtensionApi,
render,
TextField,
} from '@shopify/checkout-ui-extensions-react';
render('Checkout::Dynamic::Render', () => <App />);
function App() {
const { extensionPoint } = useExtensionApi();
const [vatNumber, setVatNumber] = useState('');
const handleVatNumberChange = (val) => {
setVatNumber(val)
}
return (
<>
<TextField
label="VAT Number (Optional)"
name="vat_number"
value={vatNumber}
onChange={(val) => handleVatNumberChange(val)}
/>
</>
);
}
hello there
Yes, it is possible to add a text field as a metafield/attribute on the checkout before the order is submitted using checkout UI extensions.
In your code example, you can use the useEffect hook to listen for changes to the vatNumber state and update the checkout information using the extensionPoint.modifyCheckout function.
Here’s an example implementation:
import React, { useState, useEffect } from 'react';
import {
useExtensionApi,
render,
TextField,
} from '@shopify/checkout-ui-extensions-react';
render('Checkout::Dynamic::Render', () =>
In this example, the `useEffect` hook listens for changes to the `vatNumber` state and updates the checkout information using the `extensionPoint.modifyCheckout` function. The new VAT number is added as an attribute on the checkout.
1 Like
Hi! Thank you so much for your response. I tried your code, and I got a TypeError. Am I missing something to access the modifyCheckout function?
TypeError: u.modifyCheckout is not a function
I’m running on
@Shopify_77 /checkout-ui-extensions-react@0.24.0.
Once again, thanks for your help!