Skip to main content
Login Join
Snippet · PHP

Add Custom Field to Checkout + Save Order Meta

Shared by Darshit Rajyaguru · April 28, 2026 · @woocommerce_checkout_fields

22 views
1 upvote
Back to Snippets

It will help to save the custom fields’ data, like GST No./ Notes Field/ Other Recommended Fields.
Replace the Field name and the custom field name as per the checkout page used.

add_filter( 'woocommerce_checkout_fields', function( $fields ) {

    $fields['billing']['billing_gst'] = [
        'label'       => 'GST Number',
        'placeholder' => 'Enter GST Number',
        'required'    => false,
        'class'       => ['form-row-wide'],
        'clear'       => true
    ];

    return $fields;
});


add_action( 'woocommerce_checkout_update_order_meta', function( $order_id ) {

    if ( ! empty( $_POST['billing_gst'] ) ) {
        update_post_meta( $order_id, '_billing_gst', sanitize_text_field( $_POST['billing_gst'] ) );
    }
});


add_action( 'woocommerce_admin_order_data_after_billing_address', function( $order ) {

    $gst = get_post_meta( $order->get_id(), '_billing_gst', true );

    if ( $gst ) {
        echo '<p><strong>GST Number:</strong> ' . esc_html( $gst ) . '</p>';
    }
});