Automattic\WooCommerce\Blocks\Domain\Services
CheckoutFields::get_order_additional_fields_with_values
Get saved additional fields for an order without applying checkout defaults.
Method of the class: CheckoutFields{}
No Hooks.
Returns
array. An array of fields definitions as well as their values formatted for display.
Usage
$CheckoutFields = new CheckoutFields(); $CheckoutFields->get_order_additional_fields_with_values( $order, $location, $group, $context );
- $order(WC_Order) (required)
- Order object.
- $location(string) (required)
- The location to get fields for (address|contact|order).
- $group(string)
- The group to get the field value for (shipping|billing|other).
Default:'other' - $context(string)
- The context to get the field value for (edit|view).
Default:'edit'
CheckoutFields::get_order_additional_fields_with_values() CheckoutFields::get order additional fields with values code 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;
}