I would like to add a list of countries to a dropdown and it should be the exact same countries as the list of countries available in my Woocommerce installation.
I have this code but it doesn't work:
// Voeg dropdown-opties toe aan Formidable-formulierveld 177 op basis van WooCommerce-landen
add_filter('frm_setup_field_entry_options', 'add_woocommerce_countries_to_dropdown', 10, 2);
function add_woocommerce_countries_to_dropdown($options, $field) {
// Controleer of het veld het gewenste veld is in het gewenste formulier
if ($field->field_id == 177 && $field->form_id == 23) {
// Haal de lijst met landen op
$countries = wc_get_countries();
// Sorteer de landen alfabetisch op landnaam
asort($countries);
// Vul de dropdown-opties
$dropdown_options = array();
foreach ($countries as $code => $name) {
$dropdown_options[$code] = $name;
}
// Stel de opties in voor het specifieke veld
$options['options'] = $dropdown_options;
}
return $options;
}
First of all, I have references to all known Formidable hooks in the Formidable Masterminds Codex. There is no Formidable filter named frm_setup_field_entry_options that I can find. Where did you find that filter referenced?
The correct filter should be frm_setup_new_fields_vars: https://formidableforms.com/knowledgebase/frm_setup_new_fields_vars/
There is also no such function as wc_get_countries(). Where did you find that one?
Last, your code produces fatal errors on the Woo function call. You should probably ask a WooCommerce expert what you're doing wrong.
Please login or Register to submit your answer