You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: extensions/custom-delivery-instructions/src/Checkout.jsx
+14-2Lines changed: 14 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -3,37 +3,45 @@ import {useMetafield} from "@shopify/ui-extensions/checkout/preact";
3
3
import{render}from"preact";
4
4
import{useState}from"preact/hooks";
5
5
6
+
// [START custom-field.ext-index]
6
7
// 1. Export the extension
7
8
exportdefaultfunction(){
8
9
render(<Extension/>,document.body)
9
10
}
11
+
// [END custom-field.ext-index]
10
12
11
13
functionExtension(){
14
+
// [START custom-field.instruction-ui]
12
15
const{
13
16
applyMetafieldChange,
14
17
i18n: {translate},
15
18
target: {value: deliveryGroupList},
16
19
}=shopify;
17
20
const[checked,setChecked]=useState(false);
21
+
// [END custom-field.instruction-ui]
18
22
23
+
// [START custom-field.define-metafield]
19
24
// Define the metafield namespace and key
20
25
constmetafieldNamespace="yourAppNamespace"
21
26
constmetafieldKey="deliveryInstructions";
27
+
// [END custom-field.define-metafield]
22
28
29
+
// [START custom-field.use-metafield]
23
30
// Get a reference to the metafield
24
31
constdeliveryInstructions=useMetafield({
25
32
namespace: metafieldNamespace,
26
33
key: metafieldKey,
27
34
});
35
+
// [END custom-field.use-metafield]
28
36
29
37
// Guard against duplicate rendering of `shipping-option-list.render-after` target for one-time purchase and subscription sections. Calling `applyMetafieldsChange()` on the same namespace-key pair from duplicated extensions would otherwise cause an overwrite of the metafield value.
30
38
// Instead of guarding, another approach would be to prefix the metafield key when calling `applyMetafieldsChange()`. The `deliveryGroupList`'s `groupType` could be used to such effect.'
0 commit comments