case 'multiselect':
$field = '';
$value = is_array( $value ) ? $value : array_map( 'trim', (array) explode( ',', $value ) );
if ( ! empty( $args['options'] ) ) {
$field .= '';
}
break;
case 'multicheckbox':
$field = '';
$value = is_array( $value ) ? $value : array_map( 'trim', (array) explode( ',', $value ) );
if ( ! empty( $args['options'] ) ) {
$field .= ' ';
foreach ( $args['options'] as $option_key => $option_text ) {
$option_key = is_numeric( $option_key ) ? $option_text : $option_key;
$field .= '';
}
$field .= '';
}
break;
case 'file':
$field = '';
$field .= '';
// $field .= '';
$field .= '';
$field .= '';
$field .= '';
break;
}
if ( ! empty( $field ) ) {
$field_html = '';
if ( $args['label'] && 'checkbox' !== $args['type'] ) {
$field_html .= '';
}
$field_html .= '' . $field;
if ( $args['description'] ) {
$field_html .= '' . wp_kses_post( $args['description'] ) . '';
}
$field_html .= '';
$container_class = esc_attr( implode( ' ', $args['class'] ) );
$container_id = esc_attr( $args['id'] ) . '_field';
$field = sprintf( $field_container, $container_class, $container_id, $field_html );
}
return $field;
}
// Heading
// ---------------------------------------------------------------------------
public function heading_field( $field = '', $key = '', $args = array(), $value = null ) {
// Custom attribute handling.
$custom_attributes = array();
if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) {
foreach ( $args['custom_attributes'] as $attribute => $attribute_value ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
}
}
$sort = $args['priority'] ? $args['priority'] : '';
$field_html = '
' . esc_html( $args['label'] ) . '
';
$container_class = esc_attr( implode( ' ', $args['class'] ) );
$container_id = esc_attr( $args['id'] ) . '_field';
$field_container = '%3$s
';
return sprintf( $field_container, $container_class, $container_id, $field_html );
}
// Colorpicker
// ---------------------------------------------------------------------------
public function colorpicker_field( $field = '', $key = '', $args = array(), $value = null ) {
$args['type'] = 'text';
$args['maxlength'] = 7;
ob_start();
woocommerce_form_field( $key, $args, $value );
$field = ob_get_clean();
$field = str_replace( '', ' ', $field );
return $field;
}
// Country
// ---------------------------------------------------------------------------
public function country_field( $field = '', $key = '', $args = array(), $value = null ) {
static $instance = 0;
if ( $instance ) {
return $field;
}
$instance++;
ob_start();
if ( ! empty( $args['default'] ) ) {
$value = $args['default'];
}
woocommerce_form_field( $key, $args, $value );
$field = ob_get_clean();
return $field;
}
// State
// ---------------------------------------------------------------------------
public function state_field( $field = '', $key = '', $args = array(), $value = null ) {
static $instance = 0;
if ( $instance ) {
return $field;
}
$instance++;
ob_start();
if ( ! empty( $args['default'] ) ) {
$value = $args['default'];
}
woocommerce_form_field( $key, $args, $value );
$field = ob_get_clean();
return $field;
}
public function hidden_field( $field = '', $key = '', $args = array(), $value = null ) {
static $instance = 0;
if ( $instance ) {
return $field;
}
$instance++;
$field .= '';
return $field;
}
public function init() {
add_filter( 'woocommerce_form_field_radio', array( $this, 'custom_field' ), 10, 4 );
add_filter( 'woocommerce_form_field_multicheckbox', array( $this, 'custom_field' ), 10, 4 );
add_filter( 'woocommerce_form_field_multiselect', array( $this, 'custom_field' ), 10, 4 );
add_filter( 'woocommerce_form_field_select', array( $this, 'custom_field' ), 10, 4 );
add_filter( 'woocommerce_form_field_file', array( $this, 'custom_field' ), 10, 4 );
add_filter( 'woocommerce_form_field_heading', array( $this, 'heading_field' ), 10, 4 );
add_filter( 'woocommerce_form_field_colorpicker', array( $this, 'colorpicker_field' ), 10, 4 );
add_filter( 'woocommerce_form_field_country', array( $this, 'country_field' ), 10, 4 );
add_filter( 'woocommerce_form_field_state', array( $this, 'state_field' ), 10, 4 );
add_filter( 'woocommerce_form_field_hidden', array( $this, 'hidden_field' ), 10, 4 );
}
}