WooCommerce Code Reference

AgenticCheckoutUtils
in package

AgenticCheckoutUtils class.

Utility class for shared Agentic Checkout API functionality.

Table of Contents

add_items_to_cart()  : Error|null
Add items to cart from request.
add_protocol_headers()  : WP_REST_Response
Add Agentic Commerce Protocol headers to response.
calculate_status()  : string
Calculate the status of the checkout session.
clear_fulfillment_address()  : mixed
Clear fulfillment address from customer.
get_agentic_commerce_gateway()  : WC_Payment_Gateway|null
Get the agentic commerce payment gateway from available gateways.
get_shared_params()  : array<string|int, mixed>
Get the shared parameters schema for checkout session requests.
is_agentic_commerce_session()  : bool
Whether the current request is within Agentic Commerce session.
is_authorized()  : bool|WP_Error
Check if the Agentic Checkout feature is enabled and request is authorized.
set_billing_address()  : mixed
Set billing address on customer.
set_buyer_data()  : mixed
Set buyer data on customer.
set_fulfillment_address()  : mixed
Set fulfillment address on customer.
validate()  : void
Validates a session.

Methods

add_items_to_cart()

Add items to cart from request.

public static add_items_to_cart(array<string|int, mixed> $items, CartController $cart_controller, Messages $messages) : Error|null
Parameters
$items : array<string|int, mixed>

Items array from request.

$cart_controller : CartController

Cart controller instance.

$messages : Messages

Error messages instance.

Return values
Error|nullReturns error response on failure, null on success.

add_protocol_headers()

Add Agentic Commerce Protocol headers to response.

public static add_protocol_headers(WP_REST_Response $response, WP_REST_Request $request) : WP_REST_Response
Parameters
$response : WP_REST_Response

Response object.

$request : WP_REST_Request

Request object.

Return values
WP_REST_ResponseResponse with headers.

get_agentic_commerce_gateway()

Get the agentic commerce payment gateway from available gateways.

public static get_agentic_commerce_gateway(array<string|int, mixed> $available_gateways) : WC_Payment_Gateway|null

Finds the first gateway that supports agentic commerce and has the required methods.

Parameters
$available_gateways : array<string|int, mixed>

Array of available payment gateways.

Return values
WC_Payment_Gateway|nullThe agentic commerce gateway or null if not found.

get_shared_params()

Get the shared parameters schema for checkout session requests.

public static get_shared_params() : array<string|int, mixed>
Return values
array<string|int, mixed>Parameters array.

is_authorized()

Check if the Agentic Checkout feature is enabled and request is authorized.

public static is_authorized([WP_REST_Request $request = null ]) : bool|WP_Error

Validates bearer token against registered agents in the agent registry.

Parameters
$request : WP_REST_Request = null

Request object.

Return values
bool|WP_ErrorTrue if authorized, WP_Error otherwise.

set_fulfillment_address()

Set fulfillment address on customer.

public static set_fulfillment_address(array<string|int, mixed> $address, WC_Customer $customer) : mixed
Parameters
$address : array<string|int, mixed>

Address data.

$customer : WC_Customer

Customer instance.

Return values
mixed