All things Shopify and commerce
Hi all, newbie here. I'm trying to create a free shipping function that only applies to customers tagged with "Faire".
This is my run.ts
import type { RunInput, FunctionRunResult, Input } from "../generated/api"; const EMPTY_DISCOUNT: FunctionRunResult = { discounts: [], }; type Configuration = {}; export function run(input: RunInput): FunctionRunResult { const configuration: Configuration = JSON.parse( input?.discountNode?.metafield?.value ?? "{}" ); if(input?.cart?.buyerIdentity?.customer?.hasAnyTag){ return{ discounts: [ { message: "Free Shipping for Faire Customers", targets: [ { deliveryGroup: { id: "" } } ], value: { percentage: { value: 100 } } } ] } } return EMPTY_DISCOUNT; };
and this is my run.graphql
query RunInput { cart { buyerIdentity { customer { hasAnyTag(tags: ["Faire"]) } } deliveryGroups { id deliveryOptions { handle title } selectedDeliveryOption { handle title } } } discountNode { metafield(namespace: "$app:flaire-free-shipping", key: "function-configuration") { value } } }
The function deploys without error but does not work in the cart. Any help would be greatly appreciated.
You're correctly checking if the customer has the "Faire" tag. However, in the return statement, you're not specifying the deliveryGroup id for which the discount should apply. You need to populate the id field within the targets object with the appropriate delivery group id. Make sure to fetch the deliveryGroup id from the input data and assign it to the targets accordingly.
Hey Rajimulislamjoy, thanks for the quick response. I'm not sure how do I go about fetching the is for the deliveryGroup. Any tips on how to do that?
Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025