Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Shopify Function to read the applied discount codes, if a string is found set shiping to $0.00

Shopify Function to read the applied discount codes, if a string is found set shiping to $0.00

KellyEldritch
Shopify Partner
3 0 5

I have created an extension only app that has a shipping discount extension.

 

My input query:

query RunInput {
  cart {
    discountCodes {
      code
    }
  }
}

Based on the GraphQL explorer found here: shopify.dev/graphiql/storefront-graphiql

 

but I get the error:

"Error 0: Cannot query field "discountCodes" on type "Cart""

I am replacing a Shopify script that iterates through the applied discounts, looking for a specific substring in those discount names. If the substring is found, it sets the shipping cost to $0.00.

 

If discountCodes is not queryable why do I find it in the explorer? If what is found in the linked explorer is not valid, where am I to find the shape that can be queried in a clear and concise format like that GraphQL explorer?

If there is no such resource, please help me produce an input query that will give me the applied discount codes, that I can iterate looking for target strings, that if found will allow me to apply a 100% shipping discount.

Sincerely stumped,

Confused Query Quester

Replies 4 (4)

sniper2804
Shopify Partner
408 24 71

Hi,

 

I don't think Discount Codes is available in the set of input parameters in Shopify as of now.

Check available input parameters here: https://shopify.dev/docs/api/functions/reference/shipping-discounts/graphql/input

Automate & bulk assign products to shipping profile: Auto Shipping Profiles: Shipr
Calculate accurate shipping rates: Shipping Calculator: ShipMagic
Hide, rename, reorder payment methods at checkout: Payment Customization: PayMix
KellyEldritch
Shopify Partner
3 0 5

If it is not possible to get the discounts as input to a function how can I get the list of accepted discount codes and then add a shipping discount based on the strings found in that list?

KellyEldritch
Shopify Partner
3 0 5

If the discounts cannot be added to an input query, is there any to get the discount codes in an extension only Shopify App?

I have been able to get the codes via a remix app, but in the remix app I cannot change the cart to add a discount for shipping.

Can this be accomplished using the webhooks that are defined in a remix app?

 

If this is just not possible it would be very helpful if someone from Shopify could let me know as I have been beating my head against this for weeks now. If it is not possible, I need to let my client know so we can look for alternative options ASAP.

Despondently Yours,

💔📉👩‍💻

Discount-Despairing Developer

GexKKoSPmCu9i8
Shopify Partner
1 0 0

Looking for this same thing, did you ever find an answer @KellyEldritch ?