WooCommerce Code Reference

CheckoutFieldsStorage

Reads, writes, and syncs additional checkout field values stored as order and customer meta.

Used by CheckoutFields, which owns the field definitions and validation; this trait only covers where values are persisted and how they are read back.

Table of Contents

get_all_fields_from_object()  : array<string|int, mixed>
Returns an array of all fields values for a given object in a group.
get_field_from_object()  : mixed
Returns a field value for a given object.
persist_field_for_customer()  : void
Persists a field value for a given customer.
persist_field_for_order()  : void
Persists a field value for a given order. This would also optionally set the field value on the customer object if the order is linked to a registered customer.
sync_customer_additional_fields_with_order()  : void
Copies additional fields from an order to a customer.
sync_order_additional_fields_with_customer()  : void
Copies additional fields from a customer to an order.
set_array_meta()  : void
Sets a field value in an array meta, supporting routing things to billing, shipping, or additional fields, based on a prefix for the key.

Methods

get_all_fields_from_object()

Returns an array of all fields values for a given object in a group.

public get_all_fields_from_object(WC_Data $wc_object[, string $group = 'other' ][, bool $all = false ]) : array<string|int, mixed>
Parameters
$wc_object : WC_Data

The object or order to get the fields for.

$group : string = 'other'

The group to get the fields for (shipping|billing|other).

$all : bool = false

Whether to return all fields or only the ones that are still registered. Default false.

Return values
array<string|int, mixed> — An array of fields.

get_field_from_object()

Returns a field value for a given object.

public get_field_from_object(string $key, WC_Customer|WC_Order $wc_object[, string $group = 'other' ]) : mixed
Parameters
$key : string

The field key.

$wc_object : WC_Customer|WC_Order

The customer or order to get the field value for.

$group : string = 'other'

The group to get the field value for (shipping|billing|other).

Return values
mixed — The field value.

persist_field_for_customer()

Persists a field value for a given customer.

public persist_field_for_customer(string $key, mixed $value, WC_Customer $customer[, string $group = 'other' ]) : void
Parameters
$key : string

The field key.

$value : mixed

The field value.

$customer : WC_Customer

The customer to persist the field for.

$group : string = 'other'

The group to persist the field for (shipping|billing|other).

Return values
void —

persist_field_for_order()

Persists a field value for a given order. This would also optionally set the field value on the customer object if the order is linked to a registered customer.

public persist_field_for_order(string $key, mixed $value, WC_Order $order[, string $group = 'other' ][, bool $set_customer = true ]) : void
Parameters
$key : string

The field key.

$value : mixed

The field value.

$order : WC_Order

The order to persist the field for.

$group : string = 'other'

The group to persist the field for (shipping|billing|other).

$set_customer : bool = true

Whether to set the field value on the customer or not.

Return values
void —

set_array_meta()

Sets a field value in an array meta, supporting routing things to billing, shipping, or additional fields, based on a prefix for the key.

private set_array_meta(string $key, mixed $value, WC_Customer|WC_Order $wc_object, string $group) : void
Parameters
$key : string

The field key.

$value : mixed

The field value.

$wc_object : WC_Customer|WC_Order

The object to set the field value for.

$group : string

The group to set the field value for (shipping|billing|other).

Return values
void —