Re: How to Get Discount Codes already applied in Shopify Function input?

How to Get Discount Codes already applied in Shopify Function input?

Nico4
Shopify Partner
25 0 12

The graphQL (Shopify Functions - Product API) does not seem to return the Discounts or Codes already applied in the Cart (ie. Automatic Discount)

 

Graphql:

query Input($tags: [String!]!) {
  cart {
    cost {
      subtotalAmount {
        amount
      }
      totalAmount {
        amount
      }
    }
    lines {
      quantity
      cost {
        amountPerQuantity {
          amount
        }
        compareAtAmountPerQuantity {
          amount
        }
        subtotalAmount {
          amount
        }
        totalAmount {
          amount
        }
      }
      merchandise {
        __typename
        ... on ProductVariant {
          id
          product {
            doTagsMatch: hasAnyTag(tags: $tags)
            id
          }
        }
      }
    }
  }
  discountNode {
    metafield(namespace: "$app:discount-price", key: "function-configuration") {
      value
    }
  }
}

Shopify input Log. The Functions does not seem to see 30% discount with the code EXTRA is already applied in the cart/checkout

{
  "cart": {
    "cost": {
      "subtotalAmount": {
        "amount": "300.0"
      },
      "totalAmount": {
        "amount": "300.0"
      }
    },
    "lines": [
      {
        "quantity": 1,
        "cost": {
          "amountPerQuantity": {
            "amount": "100.0"
          },
          "compareAtAmountPerQuantity": null,
          "subtotalAmount": {
            "amount": "100.0"
          },
          "totalAmount": {
            "amount": "100.0"
          }
        },
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid://shopify/ProductVariant/44281460818228",
          "product": {
            "doTagsMatch": false,
            "id": "gid://shopify/Product/8085131100468"
          }
        }
      },
      {
        "quantity": 1,
        "cost": {
          "amountPerQuantity": {
            "amount": "100.0"
          },
          "compareAtAmountPerQuantity": null,
          "subtotalAmount": {
            "amount": "100.0"
          },
          "totalAmount": {
            "amount": "100.0"
          }
        },
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid://shopify/ProductVariant/45604449288500",
          "product": {
            "doTagsMatch": true,
            "id": "gid://shopify/Product/8396169052468"
          }
        }
      },
      {
        "quantity": 1,
        "cost": {
          "amountPerQuantity": {
            "amount": "100.0"
          },
          "compareAtAmountPerQuantity": null,
          "subtotalAmount": {
            "amount": "100.0"
          },
          "totalAmount": {
            "amount": "100.0"
          }
        },
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid://shopify/ProductVariant/45604736958772",
          "product": {
            "doTagsMatch": true,
            "id": "gid://shopify/Product/8396223971636"
          }
        }
      }
    ]
  },
  "discountNode": {
    "metafield": {
      "value": "{\"targetingStrategy\":\"tag\",\"tags\":[\"Sale\"],\"message\":\"10% Extra\",\"percentage\":10}"
    }
  }
}

 

Replies 9 (9)

lizk
Shopify Staff
246 58 79

Hi there 👋

Could you explain your use case why you need to access that discount information?

To learn more visit the Shopify Help Center or the Community Blog.

Nico4
Shopify Partner
25 0 12

The Merchant is asking us to replicate what we did with Shopify Scripts.

Logic:

Increase or Decrease the % of discount based on:

   - Entered Discount code

   - Product Tag

 

Example:

- User entered the Coupon Code EXTRA20 (20% discount)

- The Product has tag Sale (will get an extra 10% Off)

Result: We increase the Discount to 30%

lizk
Shopify Staff
246 58 79

Thanks for providing that additional context! 

I will provide this feedback to the team!
Keep your eyes out for new releases in this area, coming soon. 

To learn more visit the Shopify Help Center or the Community Blog.

kavishatalsania
Shopify Partner
19 0 4

When can we expect the release of this feature? 

Fabien_Sebban
Shopify Partner
45 0 18

Hi @lizk ,

Do you have any feedback on when we will be able to get the discount code as Input of the Shopify function?

BaoMai_LA
Shopify Partner
3 0 1

Same issue to me, no way get coupon code already applied in cart for now.

brumelo
Shopify Partner
2 0 0

Hi, do you have any feedback on when we will be able to get the discount code as Input of the Shopify function?

 

Thank you!

slasw7
Shopify Partner
13 0 0

Hi @lizk , 

I am facing similar problem. Here's my case:

 

Currently, our site has free shipping for purchases over $500

We'll give discount code to some customers - $300 off

 

Customer A purchases $700 worth of products. Checkout total price = $200 

i.e. shipping fees applies.

 

Customer B purchases $1000 worth of products. Checkout total price = $700

i.e. shipping fees does not apply.

 

We would like to let both customer A & B enjoy free shipping because both Customer A & B purchases over $500 worth of products before applying the discount code.

RMedia
Shopify Partner
92 8 10

Hi @slasw7 
A little late, but you can offer this type of shipping discount (based on subtotal, ie. price before other discounts) using https://apps.shopify.com/better-free-shipping
Let me know if you have any questions.

Founder @ Advanced Free Shipping, create custom free shipping rules easily.
- Set Free-Shipping by 20 parameters; products, collections, customers + more
- No need for confusing Scripts or Carrier Calculated Shipping
- To learn more about 'Advanced Free Shipping' visit our Shopify app page here.