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?
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025