Automattic\WooCommerce\StoreApi\Schemas\V1
CheckoutSchema::get_additional_fields_response
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.
Метод класса: CheckoutSchema{}
Хуков нет.
Возвращает
array.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_additional_fields_response( $wc_object );
- $wc_object(WC_Order|\WC_Customer) (обязательный)
- Order or customer to read fields from.
Код CheckoutSchema::get_additional_fields_response() CheckoutSchema::get additional fields response WC 11.2.2
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;
}