Skip to content

Commit 24c2ad2

Browse files
Add tutorial references
Add tutorial references.
2 parents c57edd1 + 561f1c0 commit 24c2ad2

4 files changed

Lines changed: 30 additions & 34 deletions

File tree

extensions/custom-delivery-instructions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"dependencies": {
77
"preact": "^10.10.x",
88
"@preact/signals": "^2.3.x",
9-
"@shopify/ui-extensions": "~2025.10.0-rc"
9+
"@shopify/ui-extensions": "2025.10.x"
1010
}
1111
}

extensions/custom-delivery-instructions/shopify.extension.toml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,14 @@ uid = "9d93ba67-d760-b256-641e-db7147a028d983fc5ddc"
1515
# and the file that contains your extension’s source code. Learn more:
1616
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/extension-targets-overview
1717

18+
# [START custom-field.ext-config]
1819
[[extensions.targeting]]
1920
module = "./src/Checkout.jsx"
2021
target = "purchase.checkout.shipping-option-list.render-after"
22+
# [END custom-field.ext-config]
2123

2224
[extensions.capabilities]
2325
# Gives your extension access to directly query Shopify’s storefront API.
2426
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/configuration#api-access
2527
api_access = true
2628

27-
# Gives your extension access to make external network calls, using the
28-
# JavaScript `fetch()` API. Learn more:
29-
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/configuration#network-access
30-
# network_access = true
31-
32-
# Loads metafields on checkout resources, including the cart,
33-
# products, customers, and more. Learn more:
34-
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/configuration#metafields
35-
36-
# [[extensions.metafields]]
37-
# namespace = "my_namespace"
38-
# key = "my_key"
39-
# [[extensions.metafields]]
40-
# namespace = "my_namespace"
41-
# key = "my_other_key"
42-
43-
# Defines settings that will be collected from merchants installing
44-
# your extension. Learn more:
45-
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/configuration#settings-definition
46-
47-
# [extensions.settings]
48-
# [[extensions.settings.fields]]
49-
# key = "banner_title"
50-
# type = "single_line_text_field"
51-
# name = "Banner title"
52-
# description = "Enter a title for the banner"

extensions/custom-delivery-instructions/src/Checkout.jsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,45 @@ import {useMetafield} from "@shopify/ui-extensions/checkout/preact";
33
import {render} from "preact";
44
import {useState} from "preact/hooks";
55

6+
// [START custom-field.ext-index]
67
// 1. Export the extension
78
export default function() {
89
render(<Extension />, document.body)
910
}
11+
// [END custom-field.ext-index]
1012

1113
function Extension() {
14+
// [START custom-field.instruction-ui]
1215
const {
1316
applyMetafieldChange,
1417
i18n: {translate},
1518
target: {value: deliveryGroupList},
1619
} = shopify;
1720
const [checked, setChecked] = useState(false);
21+
// [END custom-field.instruction-ui]
1822

23+
// [START custom-field.define-metafield]
1924
// Define the metafield namespace and key
2025
const metafieldNamespace = "yourAppNamespace"
2126
const metafieldKey = "deliveryInstructions";
27+
// [END custom-field.define-metafield]
2228

29+
// [START custom-field.use-metafield]
2330
// Get a reference to the metafield
2431
const deliveryInstructions = useMetafield({
2532
namespace: metafieldNamespace,
2633
key: metafieldKey,
2734
});
35+
// [END custom-field.use-metafield]
2836

2937
// 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.
3038
// 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.'
3139
if (!deliveryGroupList || deliveryGroupList.groupType !== 'oneTimePurchase') {
3240
return null;
3341
}
3442

35-
// Get a reference to the metafield
36-
// 3. Render a UI
43+
// [START custom-field.instruction-ui]
44+
// Render UI components
3745
return (
3846
<s-stack gap="base">
3947
<s-checkbox
@@ -45,7 +53,9 @@ function Extension() {
4553
<s-text-area
4654
label={translate('deliveryInstructions')}
4755
rows={3}
56+
// [START custom-field.update-metafield]
4857
onBlur={(event) => {
58+
// Apply the change to the metafield
4959
applyMetafieldChange({
5060
type: "updateMetafield",
5161
namespace: metafieldNamespace,
@@ -54,11 +64,13 @@ function Extension() {
5464
value: event.target.value,
5565
})
5666
}}
67+
// [END custom-field.update-metafield]
5768
value={`${deliveryInstructions?.value || ''}`}
5869
/>
5970
)}
6071
</s-stack>
6172
);
73+
// [END custom-field.instruction-ui]
6274

6375
async function handleChange() {
6476
setChecked(!checked);

package-lock.json

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)