How Do I have separate discounts on different products same store?

Topic summary

A developer successfully migrated from Shopify Script Editor to Shopify Functions for member discounts based on customer and product tags. They’re now seeking guidance on implementing additional discount types for the same store.

Two potential approaches identified:

  • Option A: Modify existing codebase to add more discount types to the target array
  • Option B: Create a new function extension via npm template, deploy to existing Partner App, and install using GraphQL

Key recommendation provided:
Creating separate function extensions is preferred as it:

  • Reduces code complexity
  • Provides better transparency in Shopify Admin
  • Allows independent enabling/disabling of discounts

Important limitations to consider:

  • Maximum 5 automatic function discounts can be enabled simultaneously
  • Only 5 code function discounts can be applied to a cart at once (may increase in future)
  • Multiple discounts on the same product are subject to discount combination rules

The discussion includes code snippets showing the current Javy-based implementation filtering subscription products based on customer/product tags.

Summarized with AI on November 10. AI used: claude-sonnet-4-5-20250929.

I have a successful Shopify function that has replaced the Script Editor (hooray!) for discounting for logged in members for certain products. The discount looks for tags in both the customer and product. Works great.

Do I need a separate file to do another discount, say logged in customers get X% off certain tagged products, and push to the same “application” in my Partner account and then install via GraphQL?

Or do I need to adapt my current code base (modified from the template) which is not obvious to me?

Here is a snippet of the current code base: (Javy based) –

export function run(input) {
  const customer1 = input.cart.buyerIdentity?.customer?.active_sub;
  console.error("customer1 value = " + customer1);
  const targets = input.cart.lines
  // Only include cart lines with a quantity of two or more
  // and a targetable product variant
  .filter(line => line.quantity >= 1 &&
    line.merchandise.__typename == "ProductVariant" && customer1 == true && line.merchandise.product.member_price == true && line.sellingPlanAllocation?.sellingPlan.name != "Delivery every 1 Month" && line.sellingPlanAllocation?.sellingPlan.name != "Delivery every 1 Month, Charge every 3 Months")
  .map(line => {
    const variant = /** @type {ProductVariant} */ (line.merchandise);
    return /** @type {Target} */ ({
      // Use the variant ID to create a discount target
      productVariant: {
        id: variant.id
      }
    });
  });

[I’m filtering out subscription products to discount only one time purchase versions, based on customer tags and product tags set up in the run.graphql file.]

I know its probably obvious, but do I:

A. Adapt the current code base to somehow add more discount types to the discount target array?

B. Create a new template using npm and deploy to my existing Partner App, install new discount function onto my store using Graphql?

Thanks.

Hi @fwallace

Congrats on your Scripts migration! :smiley:

If you can separate different discounts into multiple function extensions (generating another function in your app, as you say), that is a more ideal setup as it reduces code complexity and would be more transparent in Admin as to what discounts are being applied on the shop. It also allows enabling/disabling these discounts independently. Keep in mind the following limitations however:

  • Only 5 automatic function discounts, or 5 applied code function discounts in a cart, can be enabled at one time (this number will increase in the future)
  • Discounting the same product multiple times would be subject to discount combination rules