Checkout pages often need one more field: a gift message, a delivery note, or a reference number. WooCommerce gives you a clean spot for it with the woocommerce_after_order_notes action hook.
This guide covers where the hook fires, how to render a field from it, how to validate the value, and how to save it to the order. Each example is ready to paste into a small plugin.
What the hook does
woocommerce_after_order_notes is an action that WooCommerce introduced in version 1.0. It fires in the checkout template templates/checkout/form-shipping.php, after the Additional information fields and before the form closes. It passes one argument, the WC_Checkout object.
The hook only gives you an output point. It does not validate or save anything. You handle those steps with separate hooks, shown below.
Where the hook fires
Because your callback runs inside the checkout form, the browser submits your field with the rest of the checkout data. Nearby hooks help you pick the right position:
- woocommerce_before_order_notes fires before the order notes section, if you want your field above it.
- woocommerce_before_checkout_shipping_form and woocommerce_after_checkout_shipping_form wrap the shipping section.
- woocommerce_checkout_process fires on submit, before the order is created. You’ll use it for validation.
Render a gift message field
Build the field with woocommerce_form_field() so its markup matches the rest of the checkout. Pass the current value from $checkout->get_value() so the text survives a failed validation. For more on the function, see the WooCommerce form field guide.
<?php
add_action( 'woocommerce_after_order_notes', 'my_gift_message_field' );
function my_gift_message_field( $checkout ) {
echo '<div id="my-gift-message-field">';
woocommerce_form_field( 'my_gift_message', array(
'type' => 'textarea',
'class' => array( 'form-row-wide' ),
'label' => __( 'Gift message', 'my-textdomain' ),
'placeholder' => __( 'Write a short note for the recipient', 'my-textdomain' ),
'required' => false,
), $checkout->get_value( 'my_gift_message' ) );
echo '</div>';
}Validate the field on checkout
Validation runs on woocommerce_checkout_process. WooCommerce verifies its checkout nonce before this hook runs, so your field doesn’t need its own. Add an error with wc_add_notice() to stop the order from being placed.
<?php
add_action( 'woocommerce_checkout_process', 'my_gift_message_validate' );
function my_gift_message_validate() {
if ( empty( $_POST['my_gift_message'] ) ) {
return;
}
$message = wp_unslash( $_POST['my_gift_message'] );
if ( mb_strlen( $message ) > 300 ) {
wc_add_notice( __( 'Gift messages must be 300 characters or less.', 'my-textdomain' ), 'error' );
}
}Save the value to the order
Save the value in woocommerce_checkout_create_order, which receives the order object before WooCommerce stores it. Use the order’s meta methods rather than update_post_meta(), because orders can live outside the posts table when HPOS is enabled.
<?php
add_action( 'woocommerce_checkout_create_order', 'my_gift_message_save' );
function my_gift_message_save( $order ) {
if ( empty( $_POST['my_gift_message'] ) ) {
return;
}
$order->update_meta_data( '_my_gift_message', sanitize_textarea_field( wp_unslash( $_POST['my_gift_message'] ) ) );
}Read the value later with $order->get_meta( '_my_gift_message' ). The leading underscore marks it as private meta, so it stays out of the custom fields list.
Tip: Keep each hook to one job. Render on
woocommerce_after_order_notes, validate onwoocommerce_checkout_process, and save onwoocommerce_checkout_create_order.
Common mistakes
- Saving with update_post_meta(). Orders stored with HPOS don’t live in post meta, so use the order object.
- Skipping sanitization. Run every posted value through
sanitize_textarea_field()or a similar function before you save it. - Forgetting the default value. Without
$checkout->get_value(), the field clears after a failed validation. - Mismatched field names. The name passed to
woocommerce_form_field()must match the key in$_POSTexactly.
FAQs About woocommerce_after_order_notes
Does the field need a nonce?
Not for the field itself. WooCommerce verifies the checkout nonce before woocommerce_checkout_process runs, so your validation and save callbacks only run on a valid submission.
Can I place the field above the order notes?
Yes. Hook the same callback to woocommerce_before_order_notes instead.
Where is the value stored?
In the order meta, under the key you chose. Read it with $order->get_meta() in templates, admin screens, or emails.
What does the hook pass to my callback?
The WC_Checkout object. You can call get_value() on it, as the render example does.
Conclusion
woocommerce_after_order_notes gives you a clean output point on checkout. Render the field there, validate it on woocommerce_checkout_process, and save it on the order object.
If you need a custom checkout flow for your store, hire a WooCommerce developer or send a brief through the application form.
