Back to Community

How to Access and Display Custom Checkout Field Data in WooCommerce

Content

If you're using the 'Checkout Field Editor (Checkout Manager) for WooCommerce' plugin, you've likely added some custom fields to your checkout page. A very common challenge users face is figuring out how to access the data submitted through those fields later on—whether it's for displaying in emails, invoices, a Google Sheet, or within your own custom code.

This guide will explain where this data is stored and provide the most common methods for retrieving it.

Where is the Custom Field Data Stored?

All fields created with the Checkout Field Editor plugin are saved as Order Meta Data in your WordPress database. This data is stored in the wp_postmeta table, with the order ID acting as the post_id.

The key piece of information you need is the field's meta key. This is typically the name you gave the field when you created it in the plugin's settings. For billing and shipping fields, the key is often prefixed with billing_ or shipping_ (e.g., billing_phone_ext).

How to Retrieve Custom Field Values

The primary method for retrieving this data is by using the WordPress function get_post_meta(). You need two things: the order ID and the correct meta key for your field.

1. Basic PHP Function

The standard way to get a value is with this function:

$custom_field_value = get_post_meta( $order_id, 'your_meta_key_here', true );

Replace your_meta_key_here with the actual name of your custom field (e.g., 'billing_dni'). The true parameter ensures it returns a single value as a string.

2. WooCommerce Order Method

If you are working within the WooCommerce order ecosystem (e.g., on the thank you page, in email templates, or with hooks that provide an $order object), you can use the WooCommerce method:

$custom_field_value = $order->get_meta( 'your_meta_key_here' );

This is often considered a more modern and reliable approach within WooCommerce contexts.

Common Use Cases and Examples

Displaying a Field in a Custom Email Template

If you are editing a WooCommerce email template, you can use the order object to output your custom field.

<?php
// Example for a field named 'addburn'
$addburn_value = $order->get_meta( 'addburn' );
if ( ! empty( $addburn_value ) ) {
    echo '<p><strong>Custom Field:</strong> ' . esc_html( $addburn_value ) . '</p>';
}
?>

Creating a Shortcode to Display a Field Value

To create a shortcode that displays a custom field's value on a page, you need to securely obtain the order ID. The method for getting the order ID depends on the context (e.g., the order details page).

// Shortcode to get a custom field value (e.g., [get_custom_field field="billing_dni"])
function custom_field_shortcode( $atts ) {
    $atts = shortcode_atts( array(
        'field' => ''
    ), $atts, 'get_custom_field' );

    // Try to get the order ID from the URL if on the order-received page
    $order_id = absint( get_query_var('order-received') );

    if ( empty( $atts['field'] ) || empty( $order_id ) ) {
        return '';
    }

    return get_post_meta( $order_id, $atts['field'], true );
}
add_shortcode( 'get_custom_field', 'custom_field_shortcode' );

Passing Data to External Services (Google Sheets, PayPal)

When sending order data to an external service like Google Sheets via a webhook, you must explicitly map your custom fields. They are not included in the standard billing/shipping objects. You will find them in the order's metadata array.

In a Google Apps Script, you might access them like this:

// Inside a doPost(e) function
var myData = JSON.parse(e.postData.contents);

// Access a custom field from the meta_data array
var custom_field_value = '';
for (var i = 0; i < myData.meta_data.length; i++) {
    if (myData.meta_data[i].key == 'your_meta_key_here') {
        custom_field_value = myData.meta_data[i].value;
        break;
    }
}

Troubleshooting Tips

  • Double-Check the Meta Key: The most common issue is using an incorrect meta key. Verify the exact name of your field in the plugin's settings.
  • Enable Display in Emails: If your custom field is not showing in WooCommerce emails, ensure the "Display in Emails" option is enabled for that field within the Checkout Field Editor plugin settings.
  • Underscore Prefix Note: Be aware that WooCommerce may sometimes create a duplicate meta entry with an underscore prefix (e.g., _billing_phone_ext). For consistency, it's often recommended to explicitly define your field names with the underscore prefix in the plugin to avoid duplication.

By understanding that custom field data is stored as order meta, you can use standard WordPress and WooCommerce functions to retrieve and display it almost anywhere you need.

Related Support Threads Support