Automattic\WooCommerce\Blocks\Domain\Services
CheckoutFieldsAdmin::format_field_for_meta_box
Converts the shape of a checkout field to match whats needed in the WooCommerce meta boxes.
Метод класса: CheckoutFieldsAdmin{}
Хуков нет.
Возвращает
Массив. Formatted field.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->format_field_for_meta_box( $field, $key );
- $field(массив) (обязательный)
- The field to format.
- $key(строка) (обязательный)
- The field key. This will be used for the ID of the field when passed to the meta box.
Код CheckoutFieldsAdmin::format_field_for_meta_box() CheckoutFieldsAdmin::format field for meta box WC 10.4.3
protected function format_field_for_meta_box( $field, $key ) {
$formatted_field = array(
'id' => $key,
'label' => $field['label'],
'value' => $field['value'],
'type' => $field['type'],
'update_callback' => array( $this, 'update_callback' ),
'show' => true,
'wrapper_class' => 'form-field-wide',
);
if ( 'select' === $field['type'] ) {
$formatted_field['options'] = array_column( $field['options'], 'label', 'value' );
}
if ( 'checkbox' === $field['type'] ) {
$formatted_field['checked_value'] = '1';
$formatted_field['unchecked_value'] = '0';
}
return $formatted_field;
}