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: README.md
+68Lines changed: 68 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1063,3 +1063,71 @@ return [
1063
1063
],
1064
1064
];
1065
1065
```
1066
+
1067
+
### Real-Time Pricing Queries
1068
+
1069
+
Shopify does not emit webhooks for changes in [price catalogs for different markets](https://shopify.dev/docs/apps/build/markets/catalogs-different-markets#considerations). If you use these features, pricing stored in locally-synchronized product elements may become stale.
1070
+
1071
+
To fetch current prices directly from Shopify's API in your Twig templates, use the GraphQL client with a query that includes [contextual pricing](https://shopify.dev/docs/api/admin-graphql/latest/objects/ProductVariantContextualPricing):
1072
+
1073
+
```twig
1074
+
{# Define the GraphQL query with contextual pricing for a specific country #}
-`contextualPricing(context: {country: XX})` returns market-specific prices (use the country code directly, e.g., `GB`, `US`, `DE`)
1121
+
- Use an alias like `gbPricing:` to name the result for easy access in Twig
1122
+
- Pass the product's `shopifyId` (already a GID) directly to the query
1123
+
- The `query()` method returns the first result directly, so access `response.variants` (not `response.data.product.variants`)
1124
+
- Falls back to the default `variant.price` if contextual pricing is not available
1125
+
1126
+
> [!WARNING]
1127
+
> Real-time API calls add latency to page rendering and count against [rate limits](#rate-limits). If some staleness is acceptable, wrap the query in a [`{% cache %}` tag](https://craftcms.com/docs/5.x/reference/twig/tags.html#cache):
1128
+
>
1129
+
> ```twig
1130
+
> {% cache using key "pricing:#{product.id}:GB" for 5 minutes %}
0 commit comments