I\'m using WordPress 5.0.2
with WooCommerce 3.5.3
and I have created a select dropdown on the checkout page, it works good, however I want to add
You can use this code it will works for you
add_filter('woocommerce_form_field_select', function ($html, $unused, $args, $value) {
if (empty($args['options'])) {
return $html;
}
$option_groups = ['-' => []];
$options = '';
foreach ($args['options'] as $option_key => $option_text) {
$option = array_map('trim', explode(':', $option_text));
if (count($option) >= 2) {
$option_groups[array_shift($option)][$option_key] = implode(':', $option);
} else {
$option_groups['-'][$option_key] = $option[0];
}
}
foreach ($option_groups as $group => $option) {
if ($group !== '-') $options .= '';
}
return preg_replace('/(?: