<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mansoor Ahmad</title>
    <description>The latest articles on DEV Community by Mansoor Ahmad (@mansoordev).</description>
    <link>https://dev.to/mansoordev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F78030%2Fc08a21b2-4ca6-4eb4-b56e-d3b367ae2ffb.jpg</url>
      <title>DEV Community: Mansoor Ahmad</title>
      <link>https://dev.to/mansoordev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mansoordev"/>
    <language>en</language>
    <item>
      <title>Why Your Custom Checkout Fields Don’t Appear in WooCommerce Checkout Blocks</title>
      <dc:creator>Mansoor Ahmad</dc:creator>
      <pubDate>Tue, 03 Nov 2026 19:17:04 +0000</pubDate>
      <link>https://dev.to/mansoordev/why-your-custom-checkout-fields-dont-appear-in-woocommerce-checkout-blocks-4ep2</link>
      <guid>https://dev.to/mansoordev/why-your-custom-checkout-fields-dont-appear-in-woocommerce-checkout-blocks-4ep2</guid>
      <description>&lt;p&gt;&lt;em&gt;Classic checkout snippets don’t automatically work with Checkout Blocks. Here’s how to add, validate and retrieve a custom order field using the supported API.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You add a custom checkout field, refresh the checkout page and see nothing.&lt;/p&gt;

&lt;p&gt;There’s no obvious PHP error. The snippet is active. Changing its priority doesn’t help.&lt;/p&gt;

&lt;p&gt;Before investigating your theme or adding more CSS, check which checkout your store uses.&lt;/p&gt;

&lt;p&gt;A field registered through &lt;code&gt;woocommerce_checkout_fields&lt;/code&gt; belongs to the classic checkout approach. The Checkout block uses a different integration path.&lt;/p&gt;

&lt;p&gt;That distinction is often the missing piece.&lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll add an optional &lt;strong&gt;purchase order reference&lt;/strong&gt; to Checkout Blocks. We’ll also validate its format and retrieve the value from the resulting order.&lt;/p&gt;

&lt;p&gt;No paid plugin, React build or theme modification is required.&lt;/p&gt;

&lt;h2&gt;
  
  
  First, identify your checkout
&lt;/h2&gt;

&lt;p&gt;Open your assigned checkout page in the WordPress editor.&lt;/p&gt;

&lt;p&gt;A classic checkout commonly uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[woocommerce_checkout]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A block-based checkout contains the WooCommerce &lt;strong&gt;Checkout&lt;/strong&gt; block, with inner blocks for its different sections.&lt;/p&gt;

&lt;p&gt;If a page builder or another extension replaces your checkout, identify its integration requirements before using either approach.&lt;/p&gt;

&lt;p&gt;Here’s the kind of snippet you may already have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_checkout_fields'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$fields&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'billing'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'purchase_order_reference'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'type'&lt;/span&gt;     &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'label'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Purchase order reference'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'required'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$fields&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That does not register the field with Checkout Blocks.&lt;/p&gt;

&lt;p&gt;WooCommerce documents the differences in its &lt;a href="https://developer.woocommerce.com/docs/block-development/reference/hooks/hook-alternatives/" rel="noopener noreferrer"&gt;checkout hook compatibility reference&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This doesn’t mean every WooCommerce PHP hook stops working with Blocks. It means you need the correct extension point for the part you’re changing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we’re building
&lt;/h2&gt;

&lt;p&gt;Our field will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Appear in the checkout’s Order Information section.&lt;/li&gt;
&lt;li&gt;Be optional.&lt;/li&gt;
&lt;li&gt;Accept a reference such as &lt;code&gt;PO-104&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reject values outside our example’s format rules.&lt;/li&gt;
&lt;li&gt;Be saved with the order, rather than as a reusable customer address field.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The format restriction is a business rule for this example: up to 40 ASCII letters, numbers or hyphens. Adjust it if your customers use spaces, slashes or other characters in their references.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Use a staging site and a payment gateway’s test mode while working through this tutorial.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;WooCommerce’s guide specifies version &lt;strong&gt;8.9.0&lt;/strong&gt; as the minimum for the Additional Checkout Fields API. Use a currently supported WooCommerce release compatible with your site, rather than treating that minimum as a recommendation.&lt;/p&gt;

&lt;p&gt;See the &lt;a href="https://developer.woocommerce.com/docs/block-development/tutorials/how-to-additional-checkout-fields-guide/" rel="noopener noreferrer"&gt;official additional fields tutorial&lt;/a&gt; for the API requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Put the code in a small plugin
&lt;/h2&gt;

&lt;p&gt;Avoid adding checkout functionality directly to a parent theme’s &lt;code&gt;functions.php&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Create this folder and file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wp-content/plugins/checkout-blocks-order-reference/
└── checkout-blocks-order-reference.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="cd"&gt;/**
 * Plugin Name: Checkout Blocks Order Reference Example
 * Description: Add an optional purchase-order reference to Checkout Blocks.
 * Version: 1.0.0
 * Requires Plugins: woocommerce
 * Text Domain: swift-commerce-checkout-example
 */&lt;/span&gt;

&lt;span class="nb"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'ABSPATH'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'woocommerce_init'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'swift_commerce_example_register_order_reference'&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;swift_commerce_example_register_order_reference&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nb"&gt;function_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s1"&gt;'woocommerce_register_additional_checkout_field'&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;woocommerce_register_additional_checkout_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s1"&gt;'id'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'swift-commerce-tutorial/order-reference'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'label'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="s1"&gt;'Purchase order reference'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'swift-commerce-checkout-example'&lt;/span&gt;
            &lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'location'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'order'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'type'&lt;/span&gt;     &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'required'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'sanitize_callback'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
                &lt;span class="s1"&gt;'swift_commerce_example_sanitize_order_reference'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'validate_callback'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
                &lt;span class="s1"&gt;'swift_commerce_example_validate_order_reference'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;swift_commerce_example_sanitize_order_reference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;is_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;sanitize_text_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;swift_commerce_example_validate_order_reference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nb"&gt;preg_match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'/\A[A-Za-z0-9-]{1,40}\z/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WP_Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s1"&gt;'swift_commerce_example_invalid_order_reference'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="s1"&gt;'Use up to 40 letters, numbers or hyphens for the purchase order reference.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'swift-commerce-checkout-example'&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Activate &lt;strong&gt;Checkout Blocks Order Reference Example&lt;/strong&gt; from &lt;strong&gt;Plugins → Installed Plugins&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Add a product to your cart and open checkout. Look for the field in &lt;strong&gt;Order Information&lt;/strong&gt;, not inside the billing address.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why register on woocommerce_init?
&lt;/h3&gt;

&lt;p&gt;The registration needs to happen after WooCommerce has initialized.&lt;/p&gt;

&lt;p&gt;It also needs to be available beyond the visible checkout page. Checkout Blocks submits data through the Store API, so wrapping registration in &lt;code&gt;if ( is_checkout() )&lt;/code&gt; can prevent it from running during requests that process the field.&lt;/p&gt;

&lt;p&gt;Register the definition consistently. Let WooCommerce decide where to render it.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Choose the field location deliberately
&lt;/h2&gt;

&lt;p&gt;The location is not just a positioning preference.&lt;/p&gt;

&lt;p&gt;An order reference belongs to one purchase, so we used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'location'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'order'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For information that belongs to the customer or an address, the API also provides &lt;code&gt;contact&lt;/code&gt; and &lt;code&gt;address&lt;/code&gt; locations.&lt;/p&gt;

&lt;p&gt;Be particularly careful with &lt;code&gt;address&lt;/code&gt;: it applies to both billing and shipping, rather than acting as a billing-only field.&lt;/p&gt;

&lt;p&gt;For this example, we don’t want the reference from an earlier purchase automatically becoming the reference for a new order. An order-level field fits that requirement.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Keep sanitization and validation separate
&lt;/h2&gt;

&lt;p&gt;These callbacks have different jobs.&lt;/p&gt;

&lt;p&gt;The sanitization callback normalizes a single-line string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nb"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;sanitize_text_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The validation callback checks whether the normalized value meets our format rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;\A&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Za&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;z0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;]{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="n"&gt;\z&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An empty value passes because the field is optional.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;PO-104&lt;/code&gt; passes. A reference containing spaces or more than 40 characters fails our example’s rule.&lt;/p&gt;

&lt;p&gt;Do not rely exclusively on browser attributes or JavaScript for this check. Server-side validation still matters.&lt;/p&gt;

&lt;p&gt;Also, this callback receives a value through WooCommerce’s field API. It is not reading raw &lt;code&gt;$_POST&lt;/code&gt;, so don’t copy an old form handler into it and assume the request format is identical.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Let WooCommerce save the field
&lt;/h2&gt;

&lt;p&gt;You don’t need a second handler that reads &lt;code&gt;$_POST['purchase_order_reference']&lt;/code&gt; and manually updates order metadata.&lt;/p&gt;

&lt;p&gt;The field API handles persistence.&lt;/p&gt;

&lt;p&gt;Our field’s registered identifier is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;swift-commerce-tutorial/order-reference
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is different from the unnamespaced key in the earlier classic-checkout snippet.&lt;/p&gt;

&lt;p&gt;Keep the identifier stable after launch. Changing it later creates a different field identity; it doesn’t automatically migrate previously saved values.&lt;/p&gt;

&lt;p&gt;For storage and retrieval details, use the &lt;a href="https://developer.woocommerce.com/docs/block-development/extensible-blocks/cart-and-checkout-blocks/additional-checkout-fields/" rel="noopener noreferrer"&gt;Additional Checkout Fields API reference&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Retrieve the value from an order
&lt;/h2&gt;

&lt;p&gt;Inside an existing, authorized order-processing workflow, you can retrieve the reference like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Automattic\WooCommerce\Blocks\Package&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// $order_id comes from your existing, authorized order workflow.&lt;/span&gt;
&lt;span class="nv"&gt;$order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wc_get_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$order_id&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$order&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="n"&gt;\WC_Order&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$checkout_fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Package&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;container&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nc"&gt;CheckoutFields&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nv"&gt;$reference&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$checkout_fields&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_field_from_object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'swift-commerce-tutorial/order-reference'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nv"&gt;$order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'other'&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;is_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$reference&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nv"&gt;$reference&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$reference&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Place the &lt;code&gt;use&lt;/code&gt; statements at the top level of the PHP file, not inside a function. Run the retrieval code after WooCommerce has initialized.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;other&lt;/code&gt; group is used here for our order-level field.&lt;/p&gt;

&lt;p&gt;This example gets an order through &lt;code&gt;wc_get_order()&lt;/code&gt; rather than assuming orders live in WordPress post tables. That matters for stores using High-Performance Order Storage.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The retrieval code does not grant permission to view an order. If you build a public endpoint or customer-facing page around it, enforce authorization and order ownership before exposing the value.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  If the field still doesn’t appear
&lt;/h2&gt;

&lt;p&gt;Check these before changing the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  You’re testing the assigned checkout page
&lt;/h3&gt;

&lt;p&gt;A store can have several pages named “Checkout.” Confirm the page assignment in WooCommerce settings.&lt;/p&gt;

&lt;h3&gt;
  
  
  The page actually uses Checkout Blocks
&lt;/h3&gt;

&lt;p&gt;This example does not add the field to classic checkout or a separate checkout builder.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Order Information inner block is present
&lt;/h3&gt;

&lt;p&gt;Inspect the Checkout block’s structure in the editor if that section has been removed.&lt;/p&gt;

&lt;h3&gt;
  
  
  The plugin is active and registration runs
&lt;/h3&gt;

&lt;p&gt;Check PHP errors on staging. If the registration function is unavailable, our guard returns without registering anything.&lt;/p&gt;

&lt;h3&gt;
  
  
  Another snippet isn’t registering the same identifier
&lt;/h3&gt;

&lt;p&gt;Use one implementation for the field while debugging.&lt;/p&gt;

&lt;h3&gt;
  
  
  You aren’t expecting the old billing field’s position
&lt;/h3&gt;

&lt;p&gt;Our field belongs to the order section.&lt;/p&gt;

&lt;p&gt;Changing CSS or lowering a classic field’s priority won’t fix a registration problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test more than field visibility
&lt;/h2&gt;

&lt;p&gt;Seeing the input is the first check, not the last.&lt;/p&gt;

&lt;p&gt;Run these cases with test orders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Leave it empty and confirm checkout succeeds.&lt;/li&gt;
&lt;li&gt;Submit &lt;code&gt;PO-104&lt;/code&gt; and verify the saved value.&lt;/li&gt;
&lt;li&gt;Submit an invalid reference and confirm checkout is blocked with a useful message.&lt;/li&gt;
&lt;li&gt;Test an overlength value.&lt;/li&gt;
&lt;li&gt;Repeat as a logged-in customer and, if your store permits it, as a guest.&lt;/li&gt;
&lt;li&gt;Confirm a new checkout does not unexpectedly reuse an earlier order reference.&lt;/li&gt;
&lt;li&gt;Verify the value in the order workflow that will actually consume it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If staff need the reference in an invoice, export or fulfilment integration, test that output too. Saving a field does not automatically connect it to every third-party system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prefer configuration over maintaining a snippet?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I build Swift Commerce.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Its &lt;a href="https://swiftcommerce.io/feature/checkout-field-editor/" rel="noopener noreferrer"&gt;Checkout Field Editor&lt;/a&gt; provides a settings-based route for supported additional order fields in Checkout Blocks. That does not mean every classic-checkout capability transfers to Blocks, so check the supported field types and limitations for your setup.&lt;/p&gt;

&lt;p&gt;The standalone code above does not require Swift Commerce. Use it when a small, code-managed field suits the project. If a merchant needs to maintain fields themselves, a configuration interface may be more appropriate.&lt;/p&gt;

&lt;p&gt;The important part is choosing the integration that matches the checkout you actually run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A classic checkout field that disappears in Blocks may not be broken code. It may be code targeting a different checkout.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>woocommerce</category>
      <category>php</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
