Automattic\WooCommerce\StoreApi\Schemas\V1

CheckoutSchema::get_additional_fields_responseprotectedWC 1.0

Get the additional fields response.

For an order the response falls back to customer-mirrored values; for a customer it reads the customer meta directly.

Method of the class: CheckoutSchema{}

No Hooks.

Returns

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_additional_fields_response( $wc_object );
$wc_object(WC_Order|\WC_Customer) (required)
Order or customer to read fields from.

CheckoutSchema::get_additional_fields_response() code WC 10.9.1

protected function get_additional_fields_response( \WC_Data $wc_object ) {
	$fields = $wc_object instanceof \WC_Order
		? wp_parse_args(
			$this->additional_fields_controller->get_all_fields_from_object( $wc_object, 'other' ),
			$this->additional_fields_controller->get_all_fields_from_object( wc()->customer, 'other' )
		)
		: $this->additional_fields_controller->get_all_fields_from_object( $wc_object, 'other' );

	$additional_field_schema = $this->get_additional_fields_schema();
	foreach ( $fields as $key => $value ) {
		if ( ! isset( $additional_field_schema[ $key ] ) ) {
			unset( $fields[ $key ] );
			continue;
		}
		// This makes sure we're casting checkboxes from "1" and "0" to boolean. In the frontend, "0" is treated as truthy.
		if ( isset( $additional_field_schema[ $key ]['type'] ) && 'boolean' === $additional_field_schema[ $key ]['type'] ) {
			$fields[ $key ] = (bool) $value;
		} else {
			$fields[ $key ] = $this->prepare_html_response( $value );
		}
	}

	return (object) $fields;
}