How to target to cartline when create Shopify Order discount function

Topic summary

A developer is building a Shopify Order discount function that needs to handle both subscription and one-time purchases. The core challenge: when a cart contains the same product variant purchased both ways (subscription + one-time), they need to target specific cart lines rather than product variants to apply discounts correctly.

Technical Context:

  • Current code uses orderSubtotal with excludedVariantIds to apply a 10% discount
  • Minimum order requirement of $100 is set
  • The existing approach doesn’t distinguish between subscription vs. one-time purchases of the same variant

Suggested Alternative:
One respondent recommends using product discount functions instead of order discounts if targeting individual lines is the goal, as this would be more straightforward for the use case. They also mention their app (Dollarlabs) can handle this scenario with built-in logic for checking purchase types (one-time vs. subscription).

Status: The thread remains unresolved with no solution posted by the original developer. A follow-up request was made to share any solution found.

Summarized with AI on October 28. AI used: claude-sonnet-4-5-20250929.

I’m creating Shopify Order discount function for both subscription order and onetime order. When my cart has both subscription product and one time product, how can I target to cartline instead of productVariant, because one time product and subscription product has same productVariant.

{
    discountApplicationStrategy: DiscountApplicationStrategy.First,
    discounts: [
      {
        value: {
          percentage: {
            value: 10,
          },
        },
        targets: [
          {
            // productVariant: {
            //   id: "gid://shopify/ProductVariant/43877796708534",
            //   quantity: 1,
            // },
            orderSubtotal: {
              excludedVariantIds: ["gid://shopify/ProductVariant/43877796708534"],
            },
          },
        ],
        conditions: [
          {
            orderMinimumSubtotal: {
              excludedVariantIds: [],
              minimumAmount: 100,
              targetType: TargetType.OrderSubtotal,
            },
          },
        ],
      },
    ],
  };
1 Like

@vomanhkien , I can’t help with the exact technicalities related to the logic in code. However this is something that we allow setting up easily on our app (Dollarlabs: Ultimate Discounts) alongside many other offers!

Here’s how an order discount of 10% which checks if “Liquid” product is in cart and is purchased as a one time order.

I’m still not clear about why you’d want to use order discount for this use case. If you want to target just one of the lines - then I’d suggest you take a look at product discount functions instead of order discounts. That’s also very straightforward to implement with our app :slightly_smiling_face:

Let me know if you have any queries / further questions and I’d be happy to help.

@vomanhkien

Since quite some time has passed since you raised this thread, I’m assuming you’ve already reached at a solution :slightly_smiling_face:

If so - can you please share the same and close this thread out so that others who stumble here might also find value.

Best,