placeholder_required_value( $args ) && 'multiselect' === $args['type'] ) {
$label .= ' *';
}
?>
field_without_placeholder(), true ) ) {
$this->placeholder( $args );
return;
}
$label = $this->placeholder_required_value( $args );
?>
is_this_required( $args ) ) {
$placeholder .= ' *';
}
return $placeholder;
}
/**
* We make sure our fields basic class exists in class array, in order to not have any style issue.
*
* @param array $args checkout field option.
* @since 1.1.0
* @return array
*/
private function make_sure_sellkit_native_classes_exists( $args ) {
$classes = $args['class'];
$defaults = [ 'sellkit-widget-checkout-fields', 'sellkit-checkout-fields-wrapper' ];
$new_classes = [];
$is_width = true;
foreach ( $defaults as $def ) {
if ( ! in_array( $def, $classes, true ) ) {
$new_classes[] = $def;
}
}
// Assign w-100 class to those fields that have not width class.
foreach ( $classes as $class ) {
if ( 'form-row-wide' === $class ) {
continue;
}
if ( false !== strpos( $class, 'w-' ) ) {
$is_width = false;
}
$new_classes[] = $class;
}
if ( true === $is_width ) {
$new_classes[] = 'w-100';
}
$args['class'] = $new_classes;
return $args;
}
/**
* Gets fields default value from database if exists.
*
* @param array $args checkout fields options.
* @param string $key checkout field key.
* @since 1.1.0
* @return array
*/
private function try_to_set_default_value( $args, $key ) {
$user = get_current_user_id();
$default = get_user_meta( $user, $key, true );
if ( ! empty( $default ) ) {
$args['default'] = $default;
}
return $args;
}
/**
* Customized html per field.
*
* @param string $field field html string.
* @param array $args checkout fields options.
* @param string $key key of field.
* @return void
* @since 1.1.0
*/
abstract public function field( $field, $args, $key );
/**
* Field final html structure.
*
* @param string $field html string.
* @param array $args checkout fields options.
* @param string $key key of field.
* @return void
* @since 1.1.0
*/
public function final_html_structure( $field, $args, $key ) {
$args = $this->additional_class( $args, $key );
$args = $this->set_required_class( $args );
$args = $this->make_sure_sellkit_native_classes_exists( $args );
$args = $this->try_to_set_default_value( $args, $key );
$class = implode( ' ', $args['class'] );
// Remove all classes of fields.
$field = preg_replace( '/class=".*?"/', '', $field, 1 );
// Remove fields label.
$field = preg_replace( '~