Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFields::persist_field_for_orderpublicWC 1.0

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.

Method of the class: CheckoutFields{}

No Hooks.

Returns

null. Nothing (null).

Usage

$CheckoutFields = new CheckoutFields();
$CheckoutFields->persist_field_for_order( $key, $value, $order, $group, $set_customer );
$key(string) (required)
The field key.
$value(mixed) (required)
The field value.
$order(WC_Order) (required)
The order to persist the field for.
$group(string)
The group to persist the field for (shipping|billing|other).
Default: 'other'
$set_customer(true|false)
Whether to set the field value on the customer or not.
Default: true

CheckoutFields::persist_field_for_order() code WC 9.9.3

public function persist_field_for_order( string $key, $value, WC_Order $order, string $group = 'other', bool $set_customer = true ) {
	$group = $this->prepare_group_name( $group );
	$this->set_array_meta( $key, $value, $order, $group );
	if ( $set_customer && $order->get_customer_id() ) {
		$customer = new WC_Customer( $order->get_customer_id() );
		$this->persist_field_for_customer( $key, $value, $customer, $group );
	}
}