For discussing the development and usage of Checkout UI extensions, post-purchase extensions, web pixels, Customer Accounts UI extensions, and POS UI extensions
I need help to understand why i not got value based on following code -
Its working fine order note is showing on the checkout but no value on order note , can anyone help me ?
I also get the same error but I have completed this task with the help of metafields if it helps you.
Here is the code
import {
extension,
TextField,
BlockStack,
Checkbox,
} from "@shopify/ui-extensions/checkout";
// Set the entry point for the extension
export default extension("purchase.checkout.payment-method-list.render-after", (root, api) => {
// Keep track of the UI state
const state = {
metafields: api.metafields.current,
showDeliveryInstructions: false,
};
// Render the initial extension UI
renderUI({ root, api, state });
// Keep track if metafields change. If they do, then re-render.
api.metafields.subscribe((newMetafields) => {
state.metafields = newMetafields;
renderUI({ root, api, state });
});
});
function renderUI({ root, api, state }) {
const { applyMetafieldChange } = api;
// In case this is a re-render, then remove all previous children
for (const child of root.children) {
root.removeChild(child);
}
// Define the metafield namespace and key
const metafieldNamespace = "custom";
const metafieldKey = "delivery_instructions";
// Get a reference to the metafield
const delivery_instructions = state.metafields?.find(
(field) =>
field.namespace === metafieldNamespace && field.key === metafieldKey
);
// Create the Checkbox component
const app = root.createComponent(BlockStack, {}, [
root.createComponent(
Checkbox,
{
checked: state.showDelivery_instructions,
onChange: () => {
state.showDelivery_instructions = !state.showDelivery_instructions;
renderUI({ root, api, state });
},
},
"Provide delivery instructions"
),
]);
// If the Checkbox component is selected, then create a TextField component
if (state.showDelivery_instructions) {
app.appendChild(
root.createComponent(TextField, {
multiline: 3,
label: "Delivery instructions",
onChange: (value) => {
// Apply the change to the metafield
applyMetafieldChange({
type: "updateMetafield",
namespace: metafieldNamespace,
key: metafieldKey,
valueType: "string",
note:`there comes the note`,
value,
});
},
value: delivery_instructions?.value,
})
);
}
// Render the extension components
root.appendChild(app);
}
I want this value in note_attribute but it's not working Can you please guide me.