Custom Product Input Fields: Sanity Guide vs Portable Text for Cart Data

10 replies
Last updated: Jul 7, 2022
Question: would this be the guide I need to follow if I wanted to add custom input fields on my single products page for customers to input their desired customizable text, colors, and more customizable features on a product? Would this take that information from the customer and when they press my add to cart button it sends that information with the original product name, price, etc to the cart. And then when the purchase is successful it sends it to either my sanity studio or an automated email? That's what I'm trying to do but the guide although we'll written is a little bit out of my realm of experience. But ill struggle through it I just want to make sure I'm in the right place. https://www.sanity.io/guides/custom-input-3rd-party-dataB550

OR

Is it portable text I'm trying to achieve?
AI Update

No, this guide isn't what you need! I can see why there's confusion here, so let me clarify:

What that guide is for: The custom input guide is about creating custom fields inside Sanity Studio (your content management interface) that pull data from external APIs. It's for content editors managing products in Sanity, not for customers on your storefront.

What you actually need: You're trying to add custom product options (text, colors, customizations) on your customer-facing product pages and pass that data through checkout. This is entirely frontend/e-commerce platform work, not a Sanity Studio customization.

Here's what you should do instead:

If you're using Shopify:

  • Look into Shopify line item properties - this lets customers add custom text/options that get passed to cart and checkout
  • You'd add custom input fields to your product template, then those values attach to the cart item

If you're using WooCommerce:

  • Search for "WooCommerce custom product fields" or look at plugins like WooCommerce Product Add-Ons
  • You'll add custom fields to your product page that save as order item meta data

Where Sanity fits in: Sanity would store your product information (name, price, description, images), but the customization inputs and cart functionality happen in your frontend code and e-commerce platform. After purchase, you could use Sanity Functions to receive order data via webhook and save it to Sanity, or just have it emailed to you through your e-commerce platform's built-in order notifications.

Portable Text is also not what you need - that's for rich text content editing in Sanity Studio.

You're looking at backend CMS customization when you need frontend e-commerce development. Hope this saves you some time!

Show original thread
10 replies
That's not quite what you need here. Are customers able to choose any color, or are they selecting from a set of available colors. Is the text just a string field?
Whichever would be easier to implement. I assume a required text string where they can put any color, and any text (another required text string)
For the third option I'd like a dropdown box with about 10 font options but if a string would be a lot easier to implement I would probably opt for that.
But I need these fields to be required before they can add to cart, and I need to be able to access this information via sanity studio or my email
You'll need to create some sort of form with validation on your frontend, then. That's going to be outside of the realm of Sanity. The only time that would interact with your content is if you're doing something like writing orders to your content lake after they're placed.
Is react hook form compatible? I feel like that would be a good solution
Yep! It's a React component so you can use that package.
Beautiful. Final question, is there anything specific I should do while installing react hook form with npm? I tried messing with some packages and dependencies in my previous attempt at building this project and it broke my sanity studio. How can I properly install the package for react hook form? Which directory does it go in? Pleasr be as specific as possible, this is my first react app and I'm not familiar with package libraries very much. My project structure is repos/ecom/nailedit/sanity
Nailed It is where next.js lives and sanity is obviously all of my sanity files

Would I cd to the nailedit directory and install the package there?
You don't want to install any of those packages in your Sanity Studio. They are entirely separate and go on your frontend. The best place to find instructions for installing packages would be on npm or the package's repo.
So install where the front end lives which is in Nailed It. Got it. Thank you

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?