| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Elementor\Modules\Checkout\Fields; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || die(); |
| 6 |
|
| 7 |
use Sellkit\Elementor\Modules\Checkout\Fields\Base; |
| 8 |
|
| 9 |
/** |
| 10 |
* Class radio. |
| 11 |
* |
| 12 |
* @since 1.1.0 |
| 13 |
*/ |
| 14 |
class Radio extends Base { |
| 15 |
/** |
| 16 |
* Type of field. |
| 17 |
* |
| 18 |
* @return string |
| 19 |
* @since 1.1.0 |
| 20 |
*/ |
| 21 |
public function type() { |
| 22 |
return 'radio'; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Radio field wrapper classes. |
| 27 |
* |
| 28 |
* @param array $args checkout field option. |
| 29 |
* @since 1.1.0 |
| 30 |
* @return string |
| 31 |
*/ |
| 32 |
private function wrapper_class( $args ) { |
| 33 |
$class = 'radio_wrapper'; |
| 34 |
|
| 35 |
if ( 'list' === $args['mode'] ) { |
| 36 |
$class .= ' radio-wrapper-w-100'; |
| 37 |
} |
| 38 |
|
| 39 |
return $class; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Customized html per field. |
| 44 |
* |
| 45 |
* @param string $field field html string. |
| 46 |
* @param array $args checkout fields options. |
| 47 |
* @param string $key key of field. |
| 48 |
* @return void |
| 49 |
* @since 1.1.0 |
| 50 |
*/ |
| 51 |
public function field( $field, $args, $key ) { |
| 52 |
$default = ''; |
| 53 |
$i = 1; |
| 54 |
|
| 55 |
if ( is_array( $args['options'] ) ) { |
| 56 |
$default = array_key_first( $args['options'] ); |
| 57 |
} |
| 58 |
|
| 59 |
if ( ! empty( $args['default'] ) ) { |
| 60 |
$default = $args['default']; |
| 61 |
} |
| 62 |
|
| 63 |
$default = trim( $default ); |
| 64 |
|
| 65 |
foreach ( $args['options'] as $value => $label ) { |
| 66 |
$checked = ''; |
| 67 |
$value = trim( $value ); |
| 68 |
if ( (string) $default === (string) $value ) { |
| 69 |
$checked = 'checked="checked"'; |
| 70 |
} |
| 71 |
|
| 72 |
$unique_id = $key . '-' . $i; |
| 73 |
?> |
| 74 |
<div class="<?php echo esc_attr( $this->wrapper_class( $args ) ); ?>"> |
| 75 |
<input id="<?php echo esc_attr( $unique_id ); ?>" type="radio" value="<?php echo esc_attr( $value ); ?>" <?php echo $checked; ?> name="<?php echo esc_attr( $key ); ?>"> |
| 76 |
<label for="<?php echo esc_attr( $unique_id ); ?>"><?php echo esc_html( $label ); ?></label> |
| 77 |
</div> |
| 78 |
<?php |
| 79 |
|
| 80 |
$i++; |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|