Skip to content

Instantly share code, notes, and snippets.

@emre-edu-tech
Created August 13, 2024 08:36
Show Gist options
  • Save emre-edu-tech/b6d217ae850ad7b10a3c09eec834788c to your computer and use it in GitHub Desktop.
Save emre-edu-tech/b6d217ae850ad7b10a3c09eec834788c 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