App reviews, troubleshooting, and recommendations
I am trying to add data to a order meta field using shopify checkout ui extensions.
trying to figure out a way when a transaction or order placement is completed then how to pass/update data in order metafields.
my code works when I do it other way that is creating an input in ui and getting its value to pass it to applymetafieldchanges hook but is there any way i can directly update metafield data.
below is code that i want to change
import React, { useState } from "react";
import {
reactExtension,
TextField,
BlockStack,
useApplyMetafieldsChange,
useMetafield,
Checkbox,
useBuyerJourneyCompleted,
} from "@shopify/ui-extensions-react/checkout";
// Set the entry point for the extension
export default reactExtension("purchase.checkout.shipping-option-list.render-after", () => <App />);
function App() {
// Set up the checkbox state
const [checked, setChecked] = useState(false);
// Define the metafield namespace and key
const metafieldNamespace = "details";
const metafieldKey = "date";
// Get a reference to the metafield
const deliveryInstructions = useMetafield({
namespace: metafieldNamespace,
key: metafieldKey,
});
// Set a function to handle updating a metafield
const applyMetafieldsChange = useApplyMetafieldsChange();
// Set a function to handle the Checkbox component's onChange event
const handleChange = () => {
setChecked(!checked);
};
// Render the extension components
return (
<BlockStack>
<Checkbox checked={checked} onChange={handleChange}>
Provide delivery instructions
</Checkbox>
{checked && (
<TextField
label="Delivery instructions"
multiline={3}
onChange={(value) => {
// Apply the change to the metafield
applyMetafieldsChange({
type: "updateMetafield",
namespace: metafieldNamespace,
key: metafieldKey,
valueType: "string",
value,
});
}}
value={deliveryInstructions?.value}
/>
)}
</BlockStack>
);
}
Hi @testingdev,
I have a simpler solution for you to create custom fields without coding. You can use the Free version of the Easify Product Options app. It only takes a few minutes to set up! Here's a quick demo on how to do it:
I believe this method is super easy, and you should definitely try the app. However, if you still prefer custom code, feel free to ignore my suggestion 😊.
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025