Checkout validation

Topic summary

Main issue: Checkout validation rules in Shopify Functions were also firing when items were added to the cart, causing error messages to appear in a fully customized cart.liquid where they couldn’t be displayed properly. The goal was to run validations only on the checkout page, not in the cart modal.

Solution: Use buyerJourneyStep to conditionally run validations only during checkout. Specifically check for the step “CHECKOUT_INTERACTION” to restrict validation to the checkout flow. The original poster confirmed this solved their problem.

Update for one-page checkout: Also check for “CHECKOUT_COMPLETION” because “CHECKOUT_INTERACTION” may not trigger when clicking Pay Now in one-page checkout.

Key concept: buyerJourneyStep is a context indicator provided to the validation function that shows the current stage of the buyer’s flow (e.g., interaction or completion in checkout).

Outcome: Resolved. Action item is to gate validation logic by buyerJourneyStep, allowing it only on CHECKOUT_INTERACTION and CHECKOUT_COMPLETION for full checkout compatibility. Discussion concluded with confirmations from participants.

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

I would like to implement a checkout validation to prevent users to complete purchase when any products in their cart matche a certain case in checkout page.

I attempted to do this by using shopify function (https://shopify.dev/docs/apps/checkout/validation/create-simple-validation-rules), but I realized that the validation is also executed when users add a item into the cart.

I know this sounds good in most cases, but not for my store theme, because the cart.liquid is fully customized using js. It does not seem to be feasible to display returned error message in proper section of my cart.liquid.

So, I would like to know if it is possible to run the validation only in checkout page, but not in cart modal.

I am still learning about all the checkout extensibility stuff.

I hope I get some answer for this.

Thanks.

I found this answer on another thread after having the same issue.

https://community.shopify.com/post/2488249

There is a buyerJourneyStep that you can use to see if they’re on “CHECKOUT_INTERACTION”

2 Likes

Hi, Philip.

Thanks!! It solves my problem!!

1 Like

Glad I could help! I just now discovered you should also check for “CHECKOUT_COMPLETION” for compatibility with one-page checkout. CHECKOUT_INTERACTION apparently doesn’t trigger on one-page checkout when clicking Pay Now.

3 Likes

Thanks for this followup Philip, you saved me a lot of time and pain!

1 Like