Thursday, 5:45 PM
The client's accountant: "Why is there no tax ID in the orders for the last two weeks?" The field was added through woocommerce_checkout_fields. Two weeks ago the checkout page was rebuilt on the Checkout block. The field just disappeared: no error, no warning in the log.
The hook didn't break. Nobody calls it.
Goal
After the lesson you explain how classic and block checkout differ, and before moving to blocks you already know which hooks will stop working.
Key concepts
- Classic: the
shortcode, a PHP form, submitted to?wc-ajax=checkout - Block: the Checkout block on React, data through the Store API
/wc/store/v1/checkout; the default on new sites since WooCommerce 8.3 - Not working in blocks:
woocommerce_checkout_fields,woocommerce_after_order_notes,woocommerce_checkout_processand other PHP form hooks - Working in both: the cart and totals on the server (
woocommerce_cart_calculate_fees, prices, coupons), order hooks (woocommerce_order_status_*,woocommerce_payment_complete) - Store API hooks:
woocommerce_store_api_checkout_update_order_from_request,woocommerce_store_api_checkout_order_processed - Block checkout creates a draft order with the
checkout-draftstatus
Diagram
flowchart LR
subgraph C["Classic"]
C1["PHP form"] --> C2["wc-ajax=checkout"] --> C3["WC_Checkout::process_checkout()"]
C3 --> C4["woocommerce_checkout_* hooks"]
end
subgraph B["Block"]
B1["React block"] --> B2["Store API /checkout"] --> B3["Checkout route"]
B3 --> B4["woocommerce_store_api_* hooks"]
end
C4 --> O["WC_Order → payment → statuses"]
B4 --> O
Code
Processing after the order is created, for both checkouts:
<?php
// Classic checkout.
add_action( 'woocommerce_checkout_order_processed', static function ( $order_id ) {
my_after_checkout( wc_get_order( $order_id ) );
} );
// Block checkout (Store API).
add_action( 'woocommerce_store_api_checkout_order_processed', static function ( WC_Order $order ) {
my_after_checkout( $order );
} );
function my_after_checkout( ?WC_Order $order ): void {
if ( ! $order || $order->get_meta( '_my_processed' ) ) {
return; // idempotency
}
$order->update_meta_data( '_my_processed', time() );
$order->save();
}
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
A field added with woocommerce_checkout_fields isn't visible | The page uses the Checkout block | Additional Checkout Fields API (lesson 4.3) |
Validation in woocommerce_checkout_process doesn't fire | The Store API doesn't call PHP form hooks | Field API validation or Store API hooks |
| A payment plugin doesn't show up in block checkout | The payment method has no blocks integration | Register the method for blocks (lesson 6.2) |
Weak and strong answer
Question: The client moved to block checkout and "the tax ID field disappeared". What do you do?
Weak answer. Add the field again through
woocommerce_checkout_fields.
Strong answer. Block checkout doesn't read
woocommerce_checkout_fields, it works through the Store API. I register the field with the Additional Checkout Fields API with validation. I check where other parts read the field: emails, admin, export. The value is now stored under a different meta key, so I update those places. For old orders I keep reading the old key.
Why the second is stronger: The candidate knows the cause, the fix and the consequences for the data.
Practice
In the terminal: find out which page is the checkout and what's inside it, create a second page with the shortcode and compare the two. Switch the checkout page and check the result with has_block(). Make sure your woocommerce_checkout_fields filter is registered, and remember which checkout calls it.
On your own site: add a field through woocommerce_checkout_fields and open both pages. In DevTools → Network find the request block checkout sends to the Store API.
Interview Questions
The form is rendered by React on the client, and the data goes as a JSON request to the Store API. There is no PHP form template, so the hooks that inserted HTML into the form or read $_POST aren't there either.
Everything that happens to the cart and the order on the server: fee and price calculation, coupons, woocommerce_new_order, status changes, woocommerce_payment_complete.
A draft order that block checkout creates while the customer fills in the form. It isn't visible as a regular order and is cleaned up on a schedule if the purchase isn't completed.