Issue with Customer Segment and Discount Application at Checkout

I am using a customer segment to determine which customers are eligible to use a discount code. The segment checks multiple metafields on the customer. And according to Shopify documentation, they should update to include the relevant customers automatically.

The customer segment definition query looks something like this:

(metafields.system.condition = true AND metafields.system.type = 'discount') AND (metafields.system.discount_already_used != true)

Modifying the test customer’s metafields demonstrates that the segment reports correctly. Specifically, when all conditions are true, the test customer is included, and when one is false, the customer is omitted.

Despite the above, an inconsistency arises at checkout. Even if the segment indicates zero customers, the discount still applies to the test customer. The same issues occurs in a different scenario, if the segment definition changes. The customer starts out in the segment, the segment definition changes and no customers are shown, but the discount code still works for that customer at checkout.

There either seems to be a bug, caching issue, or something I’m fundamentally misunderstanding here.

I thought customer segments were a reliable way to determine if a customer is eligible to use a discount. But, I’ve been told that the behavior described is by design. Specifically, that the discount code is intentionally accepted if the “customer segment check fails”, to prevent the possible rejection of a valid code.

However, in different test scenarios, the discount application with customer segments behaves as expected. It’s only in more complex situations, like I described above, that issues arise. This makes me think this is a bug or caching issue.

If it’s truly intended to accept a discount code even when a customer doesn’t fit within a specified segment, it seems counterintuitive to the purpose of using segments to determine customer eligibility for discount codes.

Any feedback on this is much appreciated!

Hi Ap5356,

The behavior you described does sound a bit unusual. Customer segments should generally update automatically and accurately reflect the current state of your customers. However, there might be a few things happening here:

  1. Caching or Delayed Updates: It’s possible there’s a delay in updating the customer segment data. Sometimes, due to caching or other system processes, the changes made to the customer’s metafields may not be immediately reflected in the customer segment data. This could explain why the discount still applies even when it appears the customer isn’t in the segment.

  2. Discount Code Validation: The process of applying a discount code at checkout might be separate from the customer segment functionality. This means that even if a customer is not currently in a segment, if they were when the discount code was created, the system might still accept the discount code.

I would troubleshoot further by looking into the above - hope this helps!

We’ve also recently encountered issues with a discount code associated with a customer segment! This code has been working for customers logged into their accounts since 2018, but has suddenly started turning up an error that says that this “discount code isn’t available to you right now.”

This is affecting one of my client’s storefronts too.

Update here for anyone having similar issues.

Revisiting this now a couple months later, and everything appears to be working as expected. Any updates in the customer segment that I see also reliable indicate which customers are able to use the discount at checkout.

The segment of the query where I previous had this:

 AND (metafields.system.discount_already_used != true)

Was the part giving me issues. I changed the query to be more explicit, and that also seemed to solve a few problems. The end portion of the query ended up being changed from this:

(metafields.system.condition = true AND metafields.system.type = 'discount') AND (metafields.system.discount_already_used != true)

To this:

metafields.system.condition = true AND metafields.system.type = 'discount' AND metafields.system.discount_already_used = false

For whatever reason, when I used “x != true” or “x IS NOT NULL OR x = false”, the segment would show correctly, but the discount would apply incorrectly. Just switching it to x = false fixed the issues I was having.

Overall, it seems as if something changed on Shopify’s side to resolve this issue. But if you are having similar issues, perhaps try modifying your query.

I run in the exact same issue, with a customer segment defined by a query that uses two metafields:


metafields.datiutente.condition_1 = 'Si' AND metafields.discounts.condition_2 = 'Si'

In my case, when a customer no longer belongs to the customer segment, can still use the discount code.

I reached out the Support Team, and they confirmed that is an unexpected behaviour. Or better, it appears when “a response isn’t received from the check”, but it leads to wrong discount applications.

They are still investigating on the issue, hope that this could be fixed or can provide us a workaroud.