How to Add & Save Custom WooCommerce Checkout Fields

While WooCommerce provides a comprehensive default checkout flow, advanced e-commerce projects often require capturing extra information from customers—such as delivery instructions, preferred delivery dates, VAT identification numbers, or gift notes.

Instead of installing heavy checkout manager plugins that bloat your site performance, you can easily inject, validate, and save custom checkout fields using native WooCommerce hooks.

In this tutorial, we will walk through how to add a custom field to the WooCommerce checkout page and store it securely in the order metadata.

1. Injecting a Custom Field into the Checkout Form

WooCommerce provides dedicated action hooks across the checkout form. To append our custom field (for instance, delivery instructions), we hook into woocommerce_after_order_notes.

Add the following code to your custom plugin or theme’s functions.php:

				
					if (!defined('ABSPATH')) {
    exit;
}

add_action('woocommerce_after_order_notes', 'wg_woo_add_custom_checkout_field');

function wg_woo_add_custom_checkout_field($checkout) {
    echo '<div id="wg_custom_checkout_field_wrapper"><h3>' . __('Delivery Preferences', 'webgarage') . '</h3>';

    woocommerce_form_field('wg_delivery_instructions', [
        'type'        => 'textarea',
        'class'       => ['form-row-wide'],
        'label'       => __('Delivery Instructions', 'webgarage'),
        'placeholder' => __('E.g., Leave package at the back door or ring doorbell.', 'webgarage'),
        'required'    => false,
    ], $checkout->get_value('wg_delivery_instructions'));

    echo '</div>';
}
				
			

2. Validating the Custom Field Input

Before the order is processed, you should validate incoming data to ensure it complies with your requirements or character limits. We hook into woocommerce_checkout_process.

				
					add_action('woocommerce_checkout_process', 'wg_woo_validate_custom_checkout_field');

function wg_woo_validate_custom_checkout_field() {
    if (!empty($_POST['wg_delivery_instructions'])) {
        $instructions = sanitize_textarea_field($_POST['wg_delivery_instructions']);
        
        // Example validation: Limit length to 500 characters
        if (mb_strlen($instructions) > 500) {
            wc_add_notice(__('Delivery instructions must be under 500 characters.', 'webgarage'), 'error');
        }
    }
}
				
			

3. Saving the Custom Data to Order Meta

Once checkout passes validation and the order is created, we can capture our custom field value and save it directly to the order object using woocommerce_checkout_create_order.

				
					add_action('woocommerce_checkout_create_order', 'wg_woo_save_custom_checkout_field', 10, 2);

function wg_woo_save_custom_checkout_field($order, $data) {
    if (isset($_POST['wg_delivery_instructions']) && !empty($_POST['wg_delivery_instructions'])) {
        $clean_instructions = sanitize_textarea_field($_POST['wg_delivery_instructions']);
        
        // Save as custom order meta data
        $order->update_meta_data('_wg_delivery_instructions', $clean_instructions);
    }
}
				
			

4. Displaying the Custom Field in the Admin Order Screen

To ensure store managers can see these instructions when fulfilling the order, you can output the saved meta on the WooCommerce admin order detail screen:

				
					add_action('woocommerce_admin_order_data_after_billing_address', 'wg_woo_display_custom_field_in_admin', 10, 1);

function wg_woo_display_custom_field_in_admin($order) {
    $instructions = $order->get_meta('_wg_delivery_instructions');

    if (!empty($instructions)) {
        echo '<p><strong>' . __('Delivery Instructions', 'webgarage') . ':</strong><br />' . esc_html($instructions) . '</p>';
    }
}
				
			

Adding custom checkout fields programmatically keeps your WooCommerce store lightweight, fully secure, and completely tailored to your unique fulfillment workflows.

Be sure to check out our previous tutorials on WordPress development:
How to Add Custom Tabs to the MemberPress Account
How to Modify MemberPress Product Prices Dynamically
How to Handle MemberPress Events & Webhooks in PHP

Need help with your project? We will be happy to help with your project. Feel free to contact us. Just reach out and we will reply soon.

Comments

No comments yet

Share Your Thoughts

Join the conversation!

Scroll to Top

Share Your Thoughts

Thank you for your comment!

Your email address will not be published. Required fields are marked *

Pro

Thank you for reaching out! We’ll be in touch within 24 hours to discuss your project

Standard

Thank you for reaching out! We’ll be in touch within 24 hours to discuss your project

Basic

Thank you for reaching out! We’ll be in touch within 24 hours to discuss your project