Want to show extra product details, collect customer input, or make your WooCommerce listings more useful? You can add custom fields without installing another plugin. With a little custom code, you can display fields on product pages and, if needed, save the information with the order.
This guide walks you through adding WooCommerce custom product fields without a plugin, using WordPress and WooCommerce hooks. You’ll see where the code goes and how to adapt it to your store. Make a backup and test your changes on a staging site first, and you’ll be ready to customize your product pages with confidence.
Plan WooCommerce Custom Product Fields Without a Plugin
Before writing code, picture the moment a shopper encounters the new field: will it answer a question about the product, or ask the customer to provide information? That distinction helps you choose a field that fits the buying experience rather than adding friction.
Start by separating product information from customer input; the two serve different purposes and may need different handling in the cart and order.
Choose the field type and decide where it should appear
For details that vary by product, such as a material or care instruction, consider whether WooCommerce’s existing product data already covers the need. For information shoppers must enter, match the field to the answer you expect:
- Text input: a short name, engraving, or other brief personalization.
- Dropdown or radio buttons: a choice from a fixed set, such as size or gift-wrap option.
- Checkbox: a simple yes-or-no choice, such as requesting a printed receipt.
- Date field: a requested delivery or appointment date, if your store can support that choice.
Next, decide where the field belongs. A product-page field is easy to notice before adding an item to the cart, while a field shown later in checkout may suit information that applies to the whole order. Also determine whether it should appear on every product or only selected items, whether it is required, and whether its value must be carried into the cart and order. WooCommerce’s hooks and filters documentation can help you identify suitable points for displaying and processing that information.
Once the field’s purpose and placement are clear, prepare a safe place for the code. This makes testing and future maintenance much easier, especially when your theme is updated.
Back up your site and use a child theme or code snippets area
Make a complete backup of your site, including its database and files, before editing anything. Then test the change on a staging site if available; a small coding mistake can cause a visible error or interfere with the add-to-cart process.
If you add code to a theme, put it in a child theme rather than the parent theme, whose files may be replaced during an update. Alternatively, use a trusted code-snippets tool if your setup provides one. Keep each customization clearly labeled, and avoid pasting code into a theme’s template files unless you understand how those files are loaded. With a safe location chosen, you can build and test the field without putting your live storefront at unnecessary risk.
Add a Custom Field to the WooCommerce Product Page
Now that you’ve chosen what shoppers should see or enter, the next step is placing the control where it naturally fits in the buying process. A small piece of theme code can add it to the product form without changing WooCommerce’s core files.
First, choose a hook that displays the field near the add-to-cart controls. Then select the input style and check that customers can use it comfortably with a keyboard or screen reader.
Hook into the product page to display a field
WooCommerce provides actions at specific points in its templates. For a field customers should complete before adding an item, woocommercebeforeaddtocartbutton is a useful option; it places the output inside the add-to-cart form.
Add a callback to your child theme’s functions.php file or your chosen code area. This example prints a short text field. Use a distinctive name value so it won’t conflict with another customization:
addaction(
'woocommercebeforeaddtocartbutton',
'myshopproductnotefield'
);
function myshopproductnotefield() {
echo '<p class="form-row form-row-wide">';
echo '<label for="productnote">Personalization</label>';
echo '<input type="text" id="productnote" name="productnote" maxlength="60">';
echo '</p>';
}This only displays the control; it does not yet save the answer. Later, add server-side validation and cart/order handling if the value needs to follow the product through checkout.
With the display point in place, match the control to the kind of answer you need. Keep the choices concise, and avoid making an optional request appear mandatory.
Add a text, select, or checkbox input
For a fixed set of options, replace the text input with a <select> element and give each option a clear value. For example, a gift-wrap field might offer “No wrap” and “Gift wrap.” Keep the first option as a prompt, such as “Choose an option,” so shoppers don’t accidentally submit an unintended default.
A checkbox suits a simple yes-or-no request, while a text input works for brief personalization. Use an appropriate label and unique ID for each control, and set a sensible character limit for free-text answers. Required fields should also be checked on the server—not just marked with the browser’s required attribute.
Before moving on, inspect the field as a shopper would. Clear labels and predictable behavior make a custom control easier to use on both desktop and mobile.
Check the field’s markup and accessibility
Every input should have a visible label connected through matching for and id values. Don’t rely on placeholder text as the only label; it can disappear when someone starts typing and may be difficult to read.
Test the form using only a keyboard, and confirm that focus is visible and the field appears in a logical tab order. Also check that the markup sits inside the product form and that the layout remains usable on a narrow screen. These checks help make WooCommerce custom product fields without a plugin practical for more shoppers.
Save and Display WooCommerce Custom Product Field Data
A field that accepts an answer is only half the job; the value also needs to stay attached to the right product as the shopper moves through checkout. The following steps validate the submission, carry it into the order, and help you catch problems before customers do.
Start by treating browser input as untrusted: a character limit in the markup can improve the experience, but it cannot replace server-side checks. The example below keeps the field optional and rejects answers longer than 60 characters.
Validate and save the customer’s input to the cart
Add a nonce inside the product form alongside the field, then validate the request and attach a sanitized value to the cart item. These hooks can go in the same code location as the display callback:
wpnoncefield( 'myshopproductnote', 'myshopproductnotenonce' );
addfilter( 'woocommerceaddtocartvalidation', function( $passed ) {
if ( ! isset( $POST['productnote'] ) ) {
return $passed;
}
if ( ! isset( $POST['myshopproductnotenonce'] )
|| ! wpverifynonce(
sanitizetextfield( wpunslash( $POST['myshopproductnotenonce'] ) ),
'myshopproductnote'
) ) {
wcaddnotice( 'Please refresh the page and try again.', 'error' );
return false;
}
$note = sanitizetextfield( wpunslash( $POST['productnote'] ) );
if ( strlen( $note ) > 60 ) {
wcaddnotice( 'Please keep your personalization under 60 characters.', 'error' );
return false;
}
return $passed;
}, 10, 1 );
addfilter( 'woocommerceaddcartitemdata', function( $data ) {
if ( isset( $POST['productnote'] ) ) {
$note = sanitizetextfield( wpunslash( $POST['productnote'] ) );
if ( $note !== '' ) {
$data['productnote'] = $note;
}
}
return $data;
} );Keep the nonce field inside the add-to-cart form. For required input, also reject a blank value in the validation callback and show a clear notice.
Once saved with the cart item, the value can be shown during checkout and written to the order line item. That keeps personalization associated with the specific product, rather than storing it as a general order note.
Show the field value in the cart, checkout, and order details
Use WooCommerce’s item-data filter to display the value in the cart and checkout, then save it as line-item metadata when the order is created:
addfilter( 'woocommercegetitemdata', function( $itemdata, $cartitem ) {
if ( ! empty( $cartitem['productnote'] ) ) {
$itemdata[] = array(
'key' => 'Personalization',
'value' => eschtml( $cartitem['productnote'] ),
);
}
return $itemdata;
}, 10, 2 );
addaction( 'woocommercecheckoutcreateorderlineitem',
function( $item, $cartitemkey, $values ) {
if ( ! empty( $values['productnote'] ) ) {
$item->addmetadata(
'Personalization',
$values['productnote'],
true
);
}
}, 10, 3
);Check the result in the cart, checkout, and order details. WooCommerce’s hooks documentation explains these extension points.
Finally, test more than the product page itself. The add-to-cart form can behave differently depending on product type and theme templates.
Test the field on simple and variable products and troubleshoot issues
Try a simple product and a variable product, then add different answers to the cart. Confirm the value remains with the correct item, appears at checkout, and is visible in the resulting order.
- If the field is missing, check that its hook output is inside the add-to-cart form.
- If the value disappears, confirm the cart-item and order hooks are active and the field name matches exactly.
- If a variable product fails, test after selecting a variation; theme overrides or custom add-to-cart flows may need separate adjustments.
Run these checks on staging before publishing. With validation, display, and order storage working together, WooCommerce custom product fields without plugin can support a smoother, more reliable purchase flow.
Make WooCommerce Product Pages Work Better for Your Store
Adding custom fields with code gives you a flexible way to share useful product details or collect customer requests without adding another plugin. The key is to choose fields that genuinely help shoppers, place them where they make sense, and build them with accessibility and security in mind.
With a safe place for your code and careful testing from product page to order details, WooCommerce custom product fields without plugin can fit naturally into your store’s buying experience. Start with one clear need, test it on staging, and refine the field until it works smoothly for both your customers and your team.