Checkout API
The Checkout API enables you to convert shopping carts into orders, collect customer information, and process payments. It provides a complete checkout flow for headless and traditional WooCommerce implementations.Overview
The Checkout API allows you to:- Retrieve checkout session data
- Update customer billing and shipping information
- Select payment methods
- Add order notes and custom fields
- Process payment and create orders
- Handle payment gateway integration
Base Endpoint
All checkout endpoints use the base path:Authentication
Nonce Tokens
Checkout requires valid nonce tokens for all requests:The nonce is updated with each response. Always use the latest nonce from the response headers for your next request.
Cart Tokens
For headless implementations, use Cart Tokens:Get Checkout Data
Retrieve the current checkout session, including a draft order created from the cart.Request
Response
Response Fields
integer
Draft order ID created from the cart
string
Order status (typically
checkout-draft until payment is processed)string
Unique order key for verification
object
Customer billing address with email and phone
object
Customer shipping address
string
Selected payment method ID (empty until selected)
object
Payment processing results (populated after POST request)
object
Custom fields added by plugins or themes
Update Checkout Data
Update checkout information without processing payment. This is useful for persisting checkout fields as the customer fills them out.Parameters
string
The ID of the selected payment method (e.g., “bacs”, “cheque”, “stripe”)
string
Customer notes for the order
object
Custom fields with namespace/key structure (e.g.,
plugin-namespace/field-name)boolean
Set to
true to recalculate cart totals (default: false)Request
Response
The
__experimentalCart field is included when __experimental_calc_totals=true, allowing you to update the cart UI based on checkout changes without an additional request.Process Order and Payment
Submit final checkout data and process payment to create an order.Parameters
object
required
Complete billing address object
object
required
Complete shipping address object (same fields as billing except no email)
string
required
Payment method ID (e.g., “bacs”, “cheque”, “stripe”, “paypal”)
array
Payment-specific data required by the payment gateway (structure varies by gateway)
string
Order notes from the customer
string
Password for new account creation (if enabled)
boolean
Whether to create a new customer account
object
Extension-specific data
Request
Response
Payment Result Object
string
Payment outcome: “success”, “failure”, “pending”, or “error”
array
Additional payment information from the gateway
string
URL to redirect customer after successful checkout (typically order confirmation page)
Checkout Flow
1
Initialize Checkout
Make a GET request to retrieve the checkout session and pre-fill customer data
2
Collect Information
Display checkout form to collect:
- Billing address
- Shipping address
- Payment method selection
- Order notes
- Custom fields
3
Validate and Update
Optionally use PUT requests to persist data and validate fields as the customer fills out the form
4
Process Payment
Submit final checkout with POST request
5
Handle Response
- On success: Redirect to
payment_result.redirect_url - On failure: Display error message and allow retry
Payment Gateway Integration
Different payment gateways require differentpayment_data structures. Always consult the payment gateway’s documentation for specific requirements.
Example: Stripe Payment Gateway
The WooCommerce Stripe Payment Gateway expects:stripe_source is generated using the Stripe JavaScript SDK:
Example: PayPal
PayPal integration typically involves:- Generate PayPal order ID client-side
- Include PayPal order ID in
payment_data - Gateway validates and captures payment
Standard Payment Methods
WooCommerce includes built-in payment methods that don’t require additionalpayment_data:
bacs- Direct bank transfercheque- Check paymentscod- Cash on delivery
Additional Fields
Plugins can add custom checkout fields using theadditional_fields parameter:
Registering Custom Fields
Plugin developers can register custom checkout fields:Error Handling
Common Error Codes
Handling Validation Errors
Validation errors include field-specific details indata.params:
Order Statuses
After successful checkout, orders are assigned a status based on the payment method:
Most payment gateways set orders to
processing or on-hold after successful checkout.
Retrieving Order Details
After checkout, customers can retrieve their order using the Order API:Customers can only access their own orders. The order key provides authorization without requiring authentication.
Best Practices
Validate Before Submitting
Use PUT requests during checkout to validate data before final submission:Handle Payment Redirects
Some payment gateways redirect customers to external sites. Always usepayment_result.redirect_url:
Show Loading States
Checkout can take several seconds. Always show loading indicators:Retry Failed Payments
Allow customers to retry after payment failure:Security Considerations
PCI Compliance
- Use payment gateway JavaScript SDKs to collect card details
- Never send raw card numbers to your server
- Use tokens or source IDs in
payment_data
Nonce Expiration
Nonces expire after 12-24 hours. If checkout fails with invalid nonce error:- Refresh the nonce by making a GET request
- Retry the checkout with the new nonce
HTTPS Required
Always use HTTPS for checkout operations to protect customer data in transit.Next Steps
Cart API
Learn about cart management before checkout
Store API Overview
Back to Store API introduction
Payment Gateways
Browse available payment gateway extensions
Extending Checkout
Learn how to extend the checkout experience