Checkout Validation customer email

Hello, we have our public app and we want to require email for some our app shopify products at checkout. We’ve tried with checkout validation function and cart.buyerIdentity.customer.email field, but customer is null for new customers. Is there a way to get checkout form values for validation?

Hey ArtemFokin,

Heddy from Gameball here.

Unfortunately, getting checkout form values for validation directly through the Shopify API can be tricky since those fields aren’t always populated until the customer submits their information.

One workaround is to implement a custom script or app extension that checks for the email requirement on the front end before the customer reaches the checkout page. Here’s a general approach you could take:

  1. Custom Script on Cart Page: Implement a custom JavaScript script on the cart page that checks if the customer has entered an email before they proceed to checkout. If the product in the cart requires an email, and the email field is empty, you can display an alert or redirect them to a form where they must enter their email.

  2. Product-Specific Email Requirement: If certain products require an email, you could add a tag or metafield to those products that the script checks for. This way, the script only runs the email check when those specific products are in the cart.

  3. App Embed Block or Script Tag: If you’re building a public app, you can use an App Embed Block or a Script Tag to include your custom validation script on the merchant’s store. This script can then interact with the cart page to enforce your email requirement.

  4. Alternative Validation in the Checkout: If you’re working with Shopify Plus, you might consider using Shopify Scripts (Ruby) for checkout validation, but keep in mind that Shopify Scripts are limited to Shopify Plus stores.

Unfortunately, there isn’t a direct API that lets you hook into the checkout form’s email field before submission. So, using a front-end validation approach is probably your best bet.

How do you manage customer emails?