Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFields::sync_customer_additional_fields_with_order()publicWC 1.0

Copies additional fields from an order to a customer.

Method of the class: CheckoutFields{}

No Hooks.

Return

null. Nothing (null).

Usage

$CheckoutFields = new CheckoutFields();
$CheckoutFields->sync_customer_additional_fields_with_order( $order, $customer );
$order(WC_Order) (required)
The order to sync the fields for.
$customer(WC_Customer) (required)
The customer to sync the fields for.

CheckoutFields::sync_customer_additional_fields_with_order() code WC 9.0.1

public function sync_customer_additional_fields_with_order( WC_Order $order, WC_Customer $customer ) {
	foreach ( $this->groups as $group ) {
		$order_additional_fields = $this->get_all_fields_from_object( $order, $group, true );

		// Sync customer additional fields with order additional fields.
		foreach ( $order_additional_fields as $key => $value ) {
			if ( $this->is_customer_field( $key ) ) {
				$this->persist_field_for_customer( $key, $value, $customer, $group );
			}
		}
	}
}