Hello,
In regards to get rid of the shopify scripts we are migrating it to the shopify functions atm.
But, I am facing this problem which seems impossible to be solved.
Currently customers has tags like “pro_discount:25” or any certain values.
And we need to check whether customers has such tags starting with pro_discount and if he has, then we get the discount % and do the discount for each product.
Is there a way to do it using shopify functions discount api?
This is possible. I’ve done this before. It’s better to achieve it using metafields. You can inspect the ‘pro discount’ key. Afterward, you can apply a discount equal to its value.
If it must be with a tag, follow the steps below.
Input
cart → buyerIdentity → customer ->hasAnyTag or hasTags
Thank you for your reply MasterHub.
I think, hasAnyTag or hasTags are checking whether i have those tags or not and not checking whether i have tags containing string like “prod_discount”.
Also, I have no idea how to get value in the code. Could you share me the codebase you used before.
Could you please provide me more details about how can I do this using metafields?
Yes, Sure. Graphql example :
query RunInput {
cart {
buyerIdentity {
customer {
discount_value: metafield(key:"prod_discount" namespace: "example") {
value
}
}
}
}
}
Perhaps this post I created will help you understand better how to fetch and use variables.
https://community.shopify.com/post/2765385
This is the app level right. Lets say your app is used by multiple vendors, then they can have many different tags right. So when you create/update the function can we say for this vendor use this set of tags? For example when below query will be registered then it would be registered for your app’s function. And all the vendors who have installed your app will have the same code running. My problem is can we register functions for vendor level with different tags.
query RunInput($customerTag: [String!]) {
cart {
buyerIdentity {
customer {
amountSpent {
amount
}
hasTags(tags: $customerTag) {
hasTag
tag
}
}
}
}
}