Multiple hasAnyTag elements

Topic summary

Main issue: hasAnyTag on cart.buyerIdentity.customer was always returning true when checking different customer tags to hide specific payment methods.

Recent update: A platform-side issue was fixed by staff; the original reporter confirmed the function now behaves correctly.

Correct usage for multiple tags:

  • Use an array of separate strings: hasAnyTag(tags: [“tag1”, “tag2”]). This returns true if the customer has any of the listed tags.
  • Do not combine tags into a single string (e.g., “tag1,tag2” or “tag1 tag2”), which evaluates to false.

Context and alternatives:

  • The goal is to conditionally hide payment methods based on customer tags via cart.buyerIdentity.customer.hasAnyTag.
  • For product tag checks, an alternative is product.hasTags(tags: $tags), which returns a list of matches with fields { hasTag, tag } to see which tags are present.

Status: Resolved. The prior bug was fixed, and the correct syntax for multiple tag checks is clarified. Code snippets are central for implementation.

Summarized with AI on December 11. AI used: gpt-5.

Hi,

I am looking to hide the Cash on Delivery payment method for customers tagged with “tag1”, and hide another payment method for customers tagged with “tag2”. However, I’m having trouble implementing this.

I have tried using the code below, but it seems to always return true for both hasAnyTag fields:

query Input {
  cart {
    buyerIdentity {
      customer{
        hasAnyTag(tags: ["tag1"])
        hasAnyTag2 : hasAnyTag(tags: ["tag2"])
        
      }
    }
  }
}

Could you please advise on the correct code to achieve this? Thank you for your assistance.

@Nick_Wesselman

Hi @agastify – This issue should now be resolved!

It works well now. Thank you for your assistance.

@Nick_Wesselman

Hey Nick,

I have a similar question. I have a feeling the answer was in this thread, but it looks like the solution has gone missing! Would you be able to repost?

Thanks!

Edit: For context, I am also attempting to check for multiple tags using hasAnyTags with little success.

I have tried the following:

hasAnyTag(tags: [“tag1,tag2”]) - always evaluates to false
hasAnyTag(tags: [“tag1 tag2”]) - always evaluates to false
hasAnyTag(tags: [“tag1”, “tag2”]) - always evaluates to true

Hi @Acariah

This is the correct format

hasAnyTag(tags: [“tag1”, “tag2”])

it will match any of tag1 or tag2

1 Like

@agastify You can also use hasTag field to get all object tags
query Input($tags: [String!]!) {
cart {
lines {
merchandise {
…on ProductVariant {
product {
hasTags(tags: $tags) {
hasTag
tag
}
}
}
}
}
}
}