Automattic\WooCommerce\Blocks\Domain\Services
CheckoutFields::get_order_additional_fields_with_values()
Get additional fields for an order.
Метод класса: CheckoutFields{}
Хуков нет.
Возвращает
Массив
. 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 9.4.2
public function get_order_additional_fields_with_values( WC_Order $order, string $location, string $group = 'other', string $context = 'edit' ) { // Because the Additional Checkout Fields API only applies to orders created with Store API, we should not // return any values unless it was created using Store API. This is mainly to prevent "empty" checkbox values // from being shown on the order confirmation page for orders placed using the shortcode. It's rare that this // will happen but not impossible. if ( 'store-api' !== $order->get_created_via() ) { return []; } if ( 'additional' === $location ) { wc_deprecated_argument( 'location', '8.9.0', 'The "additional" location is deprecated. Use "order" instead.' ); $location = 'order'; } if ( 'additional' === $group ) { wc_deprecated_argument( 'group', '8.9.0', 'The "additional" group is deprecated. Use "other" instead.' ); $group = 'other'; } $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 ); 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; }