WooCommerce Code Reference

CheckoutFieldsFrontend
in package

Service class managing checkout fields and its related extensibility points on the frontend.

Table of Contents

$checkout_fields_controller  : CheckoutFields
Checkout field controller.
__construct()  : mixed
Sets up core fields.
edit_account_form_fields()  : mixed
Adds additional contact fields to the My Account edit account form.
edit_address_fields()  : array<string|int, mixed>
Adds additional address fields to the My Account edit address form.
init()  : mixed
Initialize hooks. This is not run Store API requests.
render_address_fields()  : mixed
Renders address fields on the account page.
render_order_address_fields()  : mixed
Renders address fields on the order details page.
render_order_other_fields()  : mixed
Renders additional fields on the order details page.
save_account_form_fields()  : mixed
Validates and saves additional address fields to the customer object on the My Account page.
save_address_fields()  : mixed
For the My Account page, save address fields. This uses the Store API endpoint for saving addresses so extensibility hooks are consistent across the codebase.
get_posted_additional_field_values()  : array<string|int, mixed>
Get posted additional field values.
render_additional_field()  : string
Render custom field.
render_additional_fields()  : string
Render custom fields.
update_additional_fields_for_customer()  : true|WP_Error
Validate and save additional fields for a given customer.

Properties

Methods

edit_address_fields()

Adds additional address fields to the My Account edit address form.

public edit_address_fields(array<string|int, mixed> $address, string $address_type) : array<string|int, mixed>
Parameters
$address : array<string|int, mixed>

Address fields.

$address_type : string

Type of address (billing or shipping).

Return values
array<string|int, mixed>Updated address fields.

render_address_fields()

Renders address fields on the account page.

public render_address_fields(string $address_type) : mixed
Parameters
$address_type : string

Type of address (billing or shipping).

Return values
mixed

render_order_address_fields()

Renders address fields on the order details page.

public render_order_address_fields(string $address_type, WC_Order $order) : mixed
Parameters
$address_type : string

Type of address (billing or shipping).

$order : WC_Order

Order object.

Return values
mixed

save_account_form_fields()

Validates and saves additional address fields to the customer object on the My Account page.

public save_account_form_fields(int $user_id) : mixed

Customer is not provided by this hook so we handle save here.

Parameters
$user_id : int

User ID.

Return values
mixed

save_address_fields()

For the My Account page, save address fields. This uses the Store API endpoint for saving addresses so extensibility hooks are consistent across the codebase.

public save_address_fields(int $user_id, string $address_type[, array<string|int, mixed> $address = [] ][, WC_Customer $customer = null ]) : mixed

The caller saves the customer object if there are no errors. Nonces are checked before this method executes.

Parameters
$user_id : int

User ID.

$address_type : string

Type of address (billing or shipping).

$address : array<string|int, mixed> = []

Address fields.

$customer : WC_Customer = null

Customer object.

Return values
mixed

get_posted_additional_field_values()

Get posted additional field values.

protected get_posted_additional_field_values(string $location, string $group[, bool $sanitize = true ]) : array<string|int, mixed>
Parameters
$location : string

The location to get fields for.

$group : string

The group to get fields for.

$sanitize : bool = true

Whether to sanitize the field values.

Return values
array<string|int, mixed>The posted field values and sanitized field values.

render_additional_field()

Render custom field.

protected render_additional_field(array<string|int, mixed> $field) : string
Parameters
$field : array<string|int, mixed>

An additional field and value.

Return values
string

render_additional_fields()

Render custom fields.

protected render_additional_fields(array<string|int, mixed> $fields) : string
Parameters
$fields : array<string|int, mixed>

List of additional fields with values.

Return values
string

update_additional_fields_for_customer()

Validate and save additional fields for a given customer.

protected update_additional_fields_for_customer(WC_Customer $customer, string $location, string $group) : true|WP_Error
Parameters
$customer : WC_Customer

Customer object.

$location : string

Location to save fields for.

$group : string

Group to save fields for.

Return values
true|WP_ErrorTrue if successful, \WP_Error if there are errors.