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.
Method of the class: CheckoutFieldsAdmin{}
No Hooks.
Returns
Array. Formatted field.
Usage
// protected - for code of main (parent) or child class $result = $this->format_field_for_meta_box( $field, $key );
- $field(array) (required)
- The field to format.
- $key(string) (required)
- 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 code WC 10.8.1
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;
}