To optimize fulfillment workflows, store owners often add custom checkout fields using optimization plugins or custom code—such as a "Delivery Instructions" text box or a "VAT Number" field. A widespread bug occurs when a customer fills out these custom fields, completes their purchase, but the data completely vanishes. The field information fails to save to the database, leaving the admin order details screen empty.
This bug happens because of a breakdown in the data sanitization and saving pipeline within WooCommerce's checkout engine. When a checkout form is submitted via AJAX, WooCommerce triggers distinct action hooks to validate and save metadata. If your custom field script is attached to the wrong action hook, or if the field input name lacks the appropriate namespace prefix, the data gets discarded during processing. Additionally, if a security validation plugin intercepts the request and strips out unrecognized post variables, your custom data will never make it into the wp_order_itemmeta database table.
The Solution
To fix the saving failure, you must verify your custom fields use proper naming conventions and hook them directly into the core save routines.
-
Apply Correct Naming Conventions: Ensure that your custom field input elements always use a distinct naming format. It is best practice to prefix them with an underscore or a clean identifier, such as
billing_my_custom_field. -
Use the Correct Save Hook: If you are building custom fields via code, verify that you are leveraging the
woocommerce_checkout_update_order_metahook to bind the form input data safely to the order ID. Use this structured approach inside your theme:
add_action('woocommerce_checkout_update_order_meta', 'save_custom_checkout_field_data');
function save_custom_checkout_field_data($order_id) {
if (!empty($_POST['billing_my_custom_field'])) {
update_post_meta($order_id, '_billing_my_custom_field', sanitize_text_field($_POST['billing_my_custom_field']));
}
}
-
Display the Metadata in Admin Dashboard: To ensure you can actually see the saved information, attach your custom field display to the admin order review layout using the
woocommerce_admin_order_data_after_shipping_addresshook.
