Automattic\WooCommerce\Blocks\Domain\Services
CheckoutFields::get_order_additional_fields_with_values
Get saved additional fields for an order without applying checkout defaults.
Метод класса: CheckoutFields{}
Хуков нет.
Возвращает
array. An array of fields definitions as well as their values formatted for display.
Использование
$CheckoutFields = new CheckoutFields(); $CheckoutFields->get_order_additional_fields_with_values( $order, $location, $group, $context );
- $order(WC_Order) (обязательный)
- Order object.
- $location(строка) (обязательный)
- The location to get fields for (address|contact|order).
- $group(строка)
- The group to get the field value for (shipping|billing|other).
По умолчанию:'other' - $context(строка)
- The context to get the field value for (edit|view).
По умолчанию:'edit'
Код CheckoutFields::get_order_additional_fields_with_values() CheckoutFields::get order additional fields with values WC 11.3.0
public function get_order_additional_fields_with_values( WC_Order $order, string $location, string $group = 'other', string $context = 'edit' ) {
$location = $this->prepare_location_name( $location );
$group = $this->prepare_group_name( $group );
$fields = $this->get_fields_for_location( $location );
$fields_with_values = [];
foreach ( $fields as $field_key => $field ) {
$value = $this->get_field_from_object( $field_key, $order, $group, false );
if ( '' === $value || null === $value ) {
continue;
}
if ( 'view' === $context ) {
$value = $this->format_additional_field_value( $value, $field );
}
$field['value'] = $value;
$fields_with_values[ $field_key ] = $field;
}
return $fields_with_values;
}