Skip to content

Instantly share code, notes, and snippets.

@dexit
Forked from emre-edu-tech/functions.php
Created November 15, 2024 12:23
Show Gist options
  • Select an option

  • Save dexit/867bc12dc8fa6b06bd793cb30828e914 to your computer and use it in GitHub Desktop.

Select an option

Save dexit/867bc12dc8fa6b06bd793cb30828e914 to your computer and use it in GitHub Desktop.
Elementor Pro Form Prepopulate Select Field in two forms (One on a page and one on a popup)
<?php
// render elementor forms select item for year_built in Angebotsanfrage form
// rerender the select field using elementor form api
add_filter('elementor_pro/forms/render/item/select', function($item, $index, $form) {
if('vehicle_quote_form' === $form->get_settings_for_display('form_name') || 'vehicle_quote_form_popup' === $form->get_settings_for_display('form_name')) {
if('year_built' == $item['custom_id'] || 'year_built_popup' == $item['custom_id']) {
$item['field_options'] = "Bitte Jahr auswählen|\n";
for($year=date('Y'); $year >= 1970; $year--) {
if($year != 1970) {
$item['field_options'] .= $year . "|" . $year . "\n";
} else {
$item['field_options'] .= $year . "|" . $year;
}
}
}
}
return $item;
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment